leocavalcante / encrypt

🔒 A set of high-level APIs over PointyCastle for two-way cryptography.
BSD 3-Clause "New" or "Revised" License
349 stars 142 forks source link

Encryption between platforms #327

Open blob84 opened 9 months ago

blob84 commented 9 months ago

If I encrypt from windows, browser or native, app doesn't decrypt on android. If I encrypt from linux, app does decrypt succesfully on android. Do you know how to create functions, encrypt and decrypt, platform independent?

Here the code:

String encryptAES(String originalText, Key secretKey) {
  final encrypter = Encrypter(AES(secretKey, mode: AESMode.cbc));
  final encrypted = encrypter.encrypt(originalText, iv: IV.fromLength(16));
  return encrypted.base64;
}

String decryptAES(String encryptedText, Key secretKey) {
  final encrypter = Encrypter(AES(secretKey, mode: AESMode.cbc));
  final encrypted = Encrypted.fromBase64(encryptedText);
  final decrypted = encrypter.decrypt(encrypted, iv: IV.fromLength(16));
  return decrypted;
}
mozomig commented 1 month ago

try save IV when you call encrypt and use it for decrypt on other platform, IV.fromLength must be return random IV each call