use of com.toshi.exception.KeyStoreException in project toshi-android-client by toshiapp.
the class HDWallet method readMasterSeedFromStorage.
private String readMasterSeedFromStorage() {
try {
final KeyStoreHandler keyStoreHandler = new KeyStoreHandler(BaseApplication.get(), ALIAS);
final String encryptedMasterSeed = this.prefs.getString(MASTER_SEED, null);
if (encryptedMasterSeed == null)
return null;
return keyStoreHandler.decrypt(encryptedMasterSeed, this::saveMasterSeed);
} catch (KeyStoreException e) {
LogUtil.exception("Error while reading master seed from storage", e);
throw new IllegalStateException(e);
}
}
use of com.toshi.exception.KeyStoreException in project toshi-android-client by toshiapp.
the class KeystoreHandler23 method encrypt.
@Override
public String encrypt(final String textToEncrypt) throws KeyStoreException {
try {
final Cipher cipher = Cipher.getInstance(TRANSFORMATION);
final GCMParameterSpec spec = new GCMParameterSpec(128, encryptionIv.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(), spec);
final byte[] encryptedData = cipher.doFinal(textToEncrypt.getBytes(UTF_8));
return Base64.encodeToString(encryptedData, Base64.DEFAULT);
} catch (NoSuchAlgorithmException | BadPaddingException | InvalidKeyException | NoSuchPaddingException | IllegalBlockSizeException | UnsupportedEncodingException | InvalidAlgorithmParameterException | java.security.KeyStoreException | UnrecoverableEntryException e) {
throw new KeyStoreException(new Throwable(e.getMessage()));
}
}
use of com.toshi.exception.KeyStoreException in project toshi-android-client by toshiapp.
the class KeyStoreBase method initKeyStore.
private void initKeyStore(final Context context) throws KeyStoreException {
this.context = context;
try {
this.keyStore = KeyStore.getInstance(ANDROID_KEY_STORE);
this.keyStore.load(null);
createNewKeysIfNeeded();
} catch (IOException | NoSuchAlgorithmException | CertificateException | java.security.KeyStoreException e) {
throw new KeyStoreException(new Throwable(e.getMessage()));
}
}
use of com.toshi.exception.KeyStoreException in project toshi-android-client by toshiapp.
the class HDWallet method saveMasterSeedToStorage.
private void saveMasterSeedToStorage(final String masterSeed) {
try {
final KeyStoreHandler keyStoreHandler = new KeyStoreHandler(BaseApplication.get(), ALIAS);
final String encryptedMasterSeed = keyStoreHandler.encrypt(masterSeed);
saveMasterSeed(encryptedMasterSeed);
this.masterSeed = masterSeed;
} catch (KeyStoreException e) {
LogUtil.exception("Error while saving master seed from storage", e);
throw new IllegalStateException(e);
}
}
use of com.toshi.exception.KeyStoreException in project toshi-android-client by toshiapp.
the class KeystoreHandler23 method decryptCurrentKeystoreVersion.
@NonNull
private String decryptCurrentKeystoreVersion(String encryptedData) throws KeyStoreException {
try {
final Cipher cipher = Cipher.getInstance(TRANSFORMATION);
final GCMParameterSpec spec = new GCMParameterSpec(128, encryptionIv.getBytes());
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(), spec);
final byte[] encryptedBytes = Base64.decode(encryptedData, Base64.DEFAULT);
final byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
return new String(decryptedBytes, UTF_8);
} catch (UnrecoverableEntryException | UnsupportedEncodingException | IllegalBlockSizeException | NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException | java.security.KeyStoreException | BadPaddingException | NoSuchAlgorithmException e) {
throw new KeyStoreException(new Throwable(e.getMessage()));
}
}
Aggregations