getting javax.crypto.BadPaddingException exception while decryption but i am using same padding method(ENCRYPTION_PADDING_PKCS7) for both enc and dec
- getting javax.crypto.BadPaddingException exception while decryption
but i am using same padding method(ENCRYPTION_PADDING_PKCS7) in android
- i am using fingerprint authorization API to enrypt the password. i am
storing cipher IV in android preferrence and using same iv to decrpt the password
***cipher initlization***
<code>
private static boolean initCipher() {
//For encryption
mCipher.init(Cipher.ENCRYPT_MODE, key);
mCipherIV = mCipher.getIV();
Log.e("SUNIL","finger::flag=="+flag+mCipherIV+"====="+key+"+"+mClientId+"+
"+mUsername+"-"+mContext);
setStringPreference(mContext, mClientId + mUsername,
FINGERPRINT_PREF_IV, new String(Base64.encode(mCipherIV,
Base64.NO_WRAP)));
//for decryption
mCipherIV = Base64.decode(getStringPreference(mContext, mClientId +
mUsername,
FINGERPRINT_PREF_IV), Base64.NO_WRAP);
IvParameterSpec ivspec = new IvParameterSpec(mCipherIV);
mCipher.init(Cipher.DECRYPT_MODE, key, ivspec);
</code>
***ENCRYPTION & DEC PART***
bytes = cryptoObject.getCipher()
.doFinal(Base64.decode(mClientSecret, Base64.NO_WRAP));
***SECRET KEY GEN***
private static SecretKey getSecretKey() {
mKeyStore.load(null);
key = (SecretKey) mKeyStore.getKey(mClientId, null);
return key;
}
Comments
Post a Comment