try {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
WalletFile walletFile = objectMapper.readValue(keystore, WalletFile.class);
ECKeyPair keyPair = Wallet.decrypt(password, walletFile);
String privateKey = keyPair.getPrivateKey().toString(16);
String publicKey = keyPair.getPublicKey().toString(16);
String address = "0x" + Keys.getAddress(publicKey);
File ff = new File(MyConst.ETH_KEYSTORE_PATH);
if (!ff.exists()) {
ff.mkdirs();
}
String generateWalletFile = walletUtils3.generateWalletFile(password, keyPair,
new File(MyConst.ETH_KEYSTORE_PATH), false);
WalletInfoBean walletInfoBean = new WalletInfoBean();
walletInfoBean.setKeyStorePath(generateWalletFile);
walletInfoBean.setWalletName(import_name.getText().toString());
walletInfoBean.setPrivateKey(privateKey);
walletInfoBean.setAddress(address);
walletInfoBean.setClick(true);
WalletSPUtils.saveWalletInfo(walletInfoBean);
show("导入成功");
getActivity().finish();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (OutOfMemoryError e) {
show("导入失败");
e.printStackTrace();
} catch (CipherException e) {
show("密码错误");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
android 区块链keyStore转换privateKey
最新推荐文章于 2023-06-17 01:38:14 发布