The code encrypted with Rijndael-128, but I need to encrypt with Rijndael-256.
I don't know how to change.
Crypto:
public class Crypto {
private static final String mEngine = "AES";
private static final String mCryptoEncrypt = "AES/ECB/ZeroBytePadding";
private String mKey;
public Crypto(String key) {
this.mKey = key;
}
public byte[] cipher(byte[] data, int mode, String crypto)
throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException,
BadPaddingException, InvalidAlgorithmParameterException {
SecretKeySpec sks =new SecretKeySpec(mKey.getBytes(Charset
.forName("UTF-8")), mEngine);
Cipher c = Cipher.getInstance(crypto);
c.init(mode, sks);
return c.doFinal(data);
}
public String encrypt(byte[] data) throws InvalidKeyException,
NoSuchAlgorithmException, NoSuchPaddingException,
IllegalBlockSizeException, BadPaddingException,
InvalidAlgorithmParameterException {
return Base64.encodeToString(cipher(data, Cipher.ENCRYPT_MODE, mCryptoEncrypt), Base64.DEFAULT);
}
}
MainActivity:
private static final String STORE_UID = "test";
private static final String AES_KEY = "0123456789123456";
Crypto crypto = new Crypto(AES_KEY);
String encode = crypto.encrypt(STORE_UID.getBytes(Charset.forName("UTF-8")));
Content:test
Key:0123456789123456
Result:vw4sykPYP90szFDu9RA4hA==
It encrypted with Rijndael-256 that should be "WEszhnxsZvq/TtK8lnwfBs91A/S8XT9oHAGC0lCRAEM="