encrypt
encrypt copied to clipboard
Create and save random IVs
Hi, i need to create a random IV and save it as String for using it later. Can someone put an example of how to do that?
Hi! I'm new so I may not be fully correct or atleast suggesting the most secure solution, but I saved the IV object by copying it's base64 string and then invoking the same method with the same string.
`Future
final encrypter = Encrypter(AES(encrKey, padding: null));
final IV iv = IV.fromBase64("srllQCNLB6/32leMbZMUUw==");
final baseString = iv.base64;
print(baseString);
final IV iv2 = IV.fromBase64(baseString);
final encryptedText = encrypter.encrypt(name, iv: iv);
final decText = encrypter.decrypt(encryptedText, iv: iv2);
print(decText);
}`
works and prints the same string each time. If i have to make it a bit stronger I would use secure random for the base64 strings and then pass the string somewhere, maybe to a different database or just send it with the encrypted text after encrypting it again with a private key . You get the idea, would love constructive feedback on the approach 🙌