Closed mhsnprvr closed 5 years ago
import 'dart:convert'; import 'dart:typed_data'; import 'package:pointycastle/api.dart'; import 'package:pointycastle/block/aes_fast.dart'; import 'package:pointycastle/export.dart'; import 'package:pointycastle/padded_block_cipher/padded_block_cipher_impl.dart'; import 'package:pointycastle/paddings/pkcs7.dart';
class Crypto { static BlockCipher aesCipher; var secretKey; static String CIPHER_TRANSFORMATION = "AES/CBC/PKCS7"; static String MESSAGEDIGEST_ALGORITHM = "MD5";
static List rawSecretKey = [ 1, 0, 12, 1, 5, 5, 9, 1, 11, 5, 1, 0, 3, 12, 10, 9 ]; static decrypt(String encrypted, String password) { print('decrypt start'); Uint8List unit8 = Uint8List.fromList(rawSecretKey); Uint8List iv = Digest(MESSAGEDIGEST_ALGORITHM).process(unit8); Uint8List passwordKey = Digest(MESSAGEDIGEST_ALGORITHM).process( utf8.encode(password), ); print('passwordKey'); CipherParameters params = PaddedBlockCipherParameters( ParametersWithIV(KeyParameter(passwordKey), iv), null); print('params'); PaddedBlockCipherImpl cipherImpl = PaddedBlockCipherImpl( PKCS7Padding(), CBCBlockCipher( AESFastEngine(), ), ); print('cipherImpl'); cipherImpl.init(false, params); print('cipher init'); print(String.fromCharCodes(cipherImpl.process( Uint8List.fromList( utf8.encode(encrypted), ), ))); return cipherImpl.process( Uint8List.fromList( utf8.encode(encrypted), ), ); } } err:Unhandled Exception: Invalid argument(s): Input data length must be a multiple of cipher's block size can you please tell me what did i do wrong?
import 'dart:convert'; import 'dart:typed_data'; import 'package:pointycastle/api.dart'; import 'package:pointycastle/block/aes_fast.dart'; import 'package:pointycastle/export.dart'; import 'package:pointycastle/padded_block_cipher/padded_block_cipher_impl.dart'; import 'package:pointycastle/paddings/pkcs7.dart';
class Crypto { static BlockCipher aesCipher; var secretKey; static String CIPHER_TRANSFORMATION = "AES/CBC/PKCS7"; static String MESSAGEDIGEST_ALGORITHM = "MD5";
static List rawSecretKey = [
1,
0,
12,
1,
5,
5,
9,
1,
11,
5,
1,
0,
3,
12,
10,
9
];
static decrypt(String encrypted, String password) {
print('decrypt start');
Uint8List unit8 = Uint8List.fromList(rawSecretKey);
Uint8List iv = Digest(MESSAGEDIGEST_ALGORITHM).process(unit8);
Uint8List passwordKey = Digest(MESSAGEDIGEST_ALGORITHM).process(
utf8.encode(password),
);
print('passwordKey');
CipherParameters params = PaddedBlockCipherParameters(
ParametersWithIV(KeyParameter(passwordKey), iv), null);
print('params');
PaddedBlockCipherImpl cipherImpl = PaddedBlockCipherImpl(
PKCS7Padding(),
CBCBlockCipher(
AESFastEngine(),
),
);
print('cipherImpl');
cipherImpl.init(false, params);
print('cipher init');
print(String.fromCharCodes(cipherImpl.process(
Uint8List.fromList(
utf8.encode(encrypted),
),
)));
return cipherImpl.process(
Uint8List.fromList(
utf8.encode(encrypted),
),
);
}
}
err:Unhandled Exception: Invalid argument(s): Input data length must be a multiple of cipher's block size
can you please tell me what did i do wrong?