decodePpkPrivateKey static method
This method takes a encryptedPrivateKey and decrypts it by useing the
provided password.
Implementation
static Uint8List decodePpkPrivateKey(
List<int> encryptedPrivateKey,
String password,
) {
var encryptedPrivateKeyList = Uint8List.fromList(encryptedPrivateKey);
var key = Uint8List(40);
SHA1Digest()
..update(Uint8List(4), 0, 4)
..update(
Uint8List.fromList(password.codeUnits),
0,
password.codeUnits.length,
)
..doFinal(key, 0);
SHA1Digest()
..update(Uint8List(4)..[3] = 1, 0, 4)
..update(
Uint8List.fromList(password.codeUnits),
0,
password.codeUnits.length,
)
..doFinal(key, 20);
final cbcBlockCipher = CBCBlockCipher(AESEngine())
..init(
false,
ParametersWithIV(KeyParameter(key.sublist(0, 32)), Uint8List(16)),
);
final seed = Uint8List(encryptedPrivateKeyList.length);
var offset = 0;
while (offset < encryptedPrivateKeyList.length) {
offset += cbcBlockCipher.processBlock(
encryptedPrivateKeyList,
offset,
seed,
offset,
);
}
assert(offset == encryptedPrivateKeyList.length);
return seed;
}