Fix cipher page example with the new cipherText class

This commit is contained in:
Hugo Pointcheval 2021-02-16 21:47:53 +01:00
parent d6f398af40
commit 189d31cf02

View File

@ -63,10 +63,10 @@ class _CipherPageState extends State<CipherPage> {
decryptionStatus.print('Encrypt before altering CipherText!'); decryptionStatus.print('Encrypt before altering CipherText!');
} else { } else {
// Add 1 to the first byte // Add 1 to the first byte
Uint8List _altered = cipherText.bytes; List<Uint8List> _altered = cipherText.bytes;
_altered[0] += 1; _altered[0][0] += 1;
// Recreate cipher text with altered data // Recreate cipher text with altered data
cipherText = AESCipherText(_altered, cipherText.iv); cipherText = AESCipherText.from(_altered, cipherText.iv);
encryptionStatus.print('String successfully encrypted.\n'); encryptionStatus.print('String successfully encrypted.\n');
encryptionStatus.append("IV: " + encryptionStatus.append("IV: " +
cipherText.iv.toString() + cipherText.iv.toString() +
@ -101,7 +101,8 @@ class _CipherPageState extends State<CipherPage> {
if (cipherText == null) { if (cipherText == null) {
decryptionStatus.print('Encrypt data before export!'); decryptionStatus.print('Encrypt data before export!');
} else { } else {
Uint8List payload = Uint8List.fromList(cipherText.iv + cipherText.bytes); // TODO: fix export format to support chunks !
Uint8List payload = cipherText.encode();
String data = TypeHelper.bytesToBase64(payload); String data = TypeHelper.bytesToBase64(payload);
decryptionStatus.print('CipherText successfully exported'); decryptionStatus.print('CipherText successfully exported');
cipherExport.print(data); cipherExport.print(data);
@ -114,9 +115,8 @@ class _CipherPageState extends State<CipherPage> {
encryptionStatus.print('CipherText import failed'); encryptionStatus.print('CipherText import failed');
} else { } else {
Uint8List payload = TypeHelper.base64ToBytes(data); Uint8List payload = TypeHelper.base64ToBytes(data);
Uint8List iv = payload.sublist(0, 16); cipherText = AESCipherText.empty();
Uint8List bytes = payload.sublist(16); cipherText.decode(payload);
cipherText = AESCipherText(bytes, iv);
encryptionStatus.print('CipherText successfully imported\n'); encryptionStatus.print('CipherText successfully imported\n');
encryptionStatus.append("IV: " + encryptionStatus.append("IV: " +
cipherText.iv.toString() + cipherText.iv.toString() +