use of org.web3j.crypto.CipherException in project SmartMesh_Android by SmartMeshFoundation.
the class WalletCopyActivity method getWalletKeyStore.
/**
* get the keyStore
* Password @ param walletPwd purse
*/
private void getWalletKeyStore(final String walletPwd) {
LoadingDialog.show(WalletCopyActivity.this, "");
new Thread(new Runnable() {
@Override
public void run() {
try {
String keyStore = WalletStorage.getInstance(getApplicationContext()).getWalletKeyStore(WalletCopyActivity.this, walletPwd, storableWallet.getPublicKey());
Message message = Message.obtain();
message.what = 1;
message.obj = keyStore;
mHandler.sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(4);
} catch (JSONException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(4);
} catch (CipherException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(3);
} catch (RuntimeException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(5);
}
}
}).start();
}
use of org.web3j.crypto.CipherException in project SmartMesh_Android by SmartMeshFoundation.
the class GesturePasswordLoginActivity method checkPwd.
/**
* access to the private key
* Password @ param walletPwd purse
*/
private void checkPwd() {
LoadingDialog.show(GesturePasswordLoginActivity.this, "");
new Thread(new Runnable() {
@Override
public void run() {
try {
Credentials keys = WalletStorage.getInstance(getApplicationContext()).getFullWallet(GesturePasswordLoginActivity.this, keyStorePwd.getText().toString().trim(), storableWallet.getPublicKey());
BigInteger privateKey = keys.getEcKeyPair().getPrivateKey();
Message message = Message.obtain();
message.obj = privateKey;
message.what = 1;
mHandler.sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(4);
} catch (JSONException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(4);
} catch (CipherException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(3);
} catch (RuntimeException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(5);
}
}
}).start();
}
use of org.web3j.crypto.CipherException in project SmartMesh_Android by SmartMeshFoundation.
the class WalletThread method run.
@Override
public void run() {
try {
String walletAddress;
if (type == 0) {
// Generate a new address 0 x...
WalletFile walletFile = OwnWalletUtils.generateNewWalletFile(password, false);
walletAddress = OwnWalletUtils.getWalletFileName(walletFile);
File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), walletAddress);
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
objectMapper.writeValue(destination, walletFile);
} else if (type == 1) {
// By private key into the new address
ECKeyPair keys = ECKeyPair.create(new BigInteger(source));
WalletFile walletFile = OwnWalletUtils.generateWalletFile(password, keys, false);
walletAddress = OwnWalletUtils.getWalletFileName(walletFile);
boolean exists = WalletStorage.getInstance(context).checkExists(walletAddress);
if (exists) {
Message message = Message.obtain();
message.what = WalletHandler.WALLET_REPEAT_ERROR;
mHandler.sendMessage(message);
return;
}
File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), walletAddress);
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
objectMapper.writeValue(destination, walletFile);
} else {
// Through the keyStore import new address
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
WalletFile walletFile = objectMapper.readValue(source, WalletFile.class);
Credentials credentials = Credentials.create(Wallet.decrypt(password, walletFile));
credentials.getEcKeyPair().getPublicKey();
walletFile = OwnWalletUtils.importNewWalletFile(password, credentials.getEcKeyPair(), false);
walletAddress = OwnWalletUtils.getWalletFileName(walletFile);
boolean exists = WalletStorage.getInstance(context).checkExists(walletAddress);
if (exists) {
Message message = Message.obtain();
message.what = WalletHandler.WALLET_REPEAT_ERROR;
mHandler.sendMessage(message);
return;
}
File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), walletAddress);
objectMapper = ObjectMapperFactory.getObjectMapper();
objectMapper.writeValue(destination, walletFile);
}
if (TextUtils.isEmpty(walletAddress)) {
mHandler.sendEmptyMessage(WalletHandler.WALLET_ERROR);
} else {
if (TextUtils.isEmpty(walletName)) {
// When import operation
walletName = Utils.getWalletName(context);
}
StorableWallet storableWallet = new StorableWallet();
storableWallet.setPublicKey(walletAddress);
storableWallet.setWalletName(walletName);
storableWallet.setPwdInfo(pwdInfo);
if (type == 0) {
storableWallet.setCanExportPrivateKey(1);
}
if (WalletStorage.getInstance(context).get().size() <= 0) {
storableWallet.setSelect(true);
}
int walletMode = MySharedPrefs.readInt(NextApplication.mContext, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_IS_WALLET_PATTERN);
if (walletMode == 1) {
MySharedPrefs.writeInt(NextApplication.mContext, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_IS_WALLET_PATTERN, 2);
WalletStorage.getInstance(context).addWalletList(storableWallet, context);
} else {
WalletStorage.getInstance(context).add(storableWallet, context);
}
if (WalletStorage.getInstance(context).get().size() > 0) {
WalletStorage.getInstance(NextApplication.mContext).updateMapDb(storableWallet.getPublicKey());
WalletStorage.getInstance(NextApplication.mContext).updateWalletToList(NextApplication.mContext, storableWallet.getPublicKey(), false);
}
mHandler.sendEmptyMessage(WalletHandler.WALLET_SUCCESS);
addAddressMethod(walletAddress);
}
return;
} catch (CipherException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(WalletHandler.WALLET_PWD_ERROR);
return;
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (RuntimeException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(WalletHandler.NO_MEMORY);
return;
} catch (Exception e) {
e.printStackTrace();
}
mHandler.sendEmptyMessage(WalletHandler.WALLET_ERROR);
}
use of org.web3j.crypto.CipherException in project SmartMesh_Android by SmartMeshFoundation.
the class WalletCopyActivity method getWalletPrivateKey.
/**
* access to the private key
* Password @ param walletPwd purse
*/
private void getWalletPrivateKey(final String walletPwd, final int type) {
LoadingDialog.show(WalletCopyActivity.this, "");
new Thread(new Runnable() {
@Override
public void run() {
try {
Credentials keys = WalletStorage.getInstance(getApplicationContext()).getFullWallet(WalletCopyActivity.this, walletPwd, storableWallet.getPublicKey());
BigInteger privateKey = keys.getEcKeyPair().getPrivateKey();
Message message = Message.obtain();
message.what = type;
message.obj = privateKey;
mHandler.sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(4);
} catch (JSONException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(4);
} catch (CipherException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(3);
} catch (RuntimeException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(5);
}
}
}).start();
}
Aggregations