Below is AES encryption method for Android, what would be the equivalent implementation in delphi for iOS.... I tried using lockbox but I don't getthe same encrypted result.
Below is AES encryption method for Android, what would be the equivalent implementation in delphi for iOS.... I tried using lockbox but I don't getthe same encrypted result.
public static String encryptAES(String password, String value) throws GeneralSecurityException, UnsupportedEncodingException {
Rfc2898DeriveBytes keyGenerator = new Rfc2898DeriveBytes(password, salt);
byte[] key = keyGenerator.getBytes(32);
byte[] iv = keyGenerator.getBytes(16);
SecretKeySpec secret = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
cipher.init(Cipher.ENCRYPT_MODE, secret, new IvParameterSpec(iv));
byte[] cipherText = cipher.doFinal(value.getBytes("UTF-16LE"));
return new String(Base64.encodeToString(cipherText, Base64.DEFAULT));
}
public static String encryptAES(String password, String value) throws GeneralSecurityException, UnsupportedEncodingException {
Rfc2898DeriveBytes keyGenerator = new Rfc2898DeriveBytes(password, salt);
byte[] key = keyGenerator.getBytes(32);
byte[] iv = keyGenerator.getBytes(16);
SecretKeySpec secret = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
cipher.init(Cipher.ENCRYPT_MODE, secret, new IvParameterSpec(iv));
byte[] cipherText = cipher.doFinal(value.getBytes("UTF-16LE"));
return new String(Base64.encodeToString(cipherText, Base64.DEFAULT));
}
Ugochukwu Mmaduekwe tested and it works OK in my iOS project.
ReplyDeleteJan Webber Macias , thanks for testing, one more thing, the code you tested included this commit right? github.com - minor refactor · Xor-el/CryptoLib4Pascal@6cfba27
ReplyDeleteUgochukwu Mmaduekwe yes
ReplyDelete