Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
add 字符串 KeyStoreFile 转换方法
Browse files Browse the repository at this point in the history
  • Loading branch information
QuincySx committed Apr 15, 2018
1 parent 630eb0e commit 2b1bbe1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public void setVersion(int version) {
this.version = version;
}

public static KeyStoreFile parse(String keystore) throws IOException {
return new ObjectMapper().readValue
(keystore, KeyStoreFile.class);
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.quincysx.crypto.CoinTypes;
import com.quincysx.crypto.ECKeyPair;
import com.quincysx.crypto.bip32.ExtendedKey;
Expand Down Expand Up @@ -136,21 +135,19 @@ protected void onCreate(Bundle savedInstanceState) {

if (master instanceof EthECKeyPair) {
try {
KeyStoreFile light = KeyStore.createStandard("123456", (EthECKeyPair) master);
KeyStoreFile light = KeyStore.createLight("123456", (EthECKeyPair) master);

Log.e("======", light.toString());
} catch (CipherException e) {
e.printStackTrace();
}
}

KeyStoreFile keyStoreFile = new ObjectMapper().readValue
("{\"address\":\"cafee4583441d2682bea06b6e8bfa722a7cea848\"," +
KeyStoreFile keyStoreFile = KeyStoreFile.parse("{\"address\":\"cafee4583441d2682bea06b6e8bfa722a7cea848\"," +
"\"id\":\"1562c4fe-c714-4187-ad62-6baff33e3633\",\"version\":3," +
"\"crypto\":{\"cipher\":\"aes-128-ctr\"," +
"\"cipherparams\":{\"iv\":\"e0ba8a361141cc01f6860170ab8ee25c\"}," +
"\"ciphertext\":\"4ee617421d4283c706c2bd48f43739d58b4aede740b62208f78cd33427419062\",\"kdf\":\"scrypt\",\"kdfparams\":{\"dklen\":32,\"n\":4096,\"p\":6,\"r\":8,\"salt\":\"85aab20aa7398f4dc0cde887c3b44c5d0ac2a5419dd6eb026272cccc55dc2588\"},\"mac\":\"29dd9c95c69611926cc826df68d65899fe11f18990d3dac7ba3778980e5a45ec\"}}",
KeyStoreFile.class);
"\"ciphertext\":\"4ee617421d4283c706c2bd48f43739d58b4aede740b62208f78cd33427419062\",\"kdf\":\"scrypt\",\"kdfparams\":{\"dklen\":32,\"n\":4096,\"p\":6,\"r\":8,\"salt\":\"85aab20aa7398f4dc0cde887c3b44c5d0ac2a5419dd6eb026272cccc55dc2588\"},\"mac\":\"29dd9c95c69611926cc826df68d65899fe11f18990d3dac7ba3778980e5a45ec\"}}");

try {
ECKeyPair decrypt = KeyStore.decrypt("123456", keyStoreFile);
Expand Down

0 comments on commit 2b1bbe1

Please sign in to comment.