encryptedPrivateKeyToSeed method
Implementation
Future<String> encryptedPrivateKeyToSeed(
String encPrivateKey, String password) async {
try {
if (encPrivateKey.isEmpty || password.isEmpty) {
return "";
}
var k = SHA3(256, SHA3_PADDING, 256);
k.update(utf8.encode(password));
final key = Uint8List.fromList(k.digest());
//print(" hash mdp = key: " + HEX.encode(key));
//print(key);
var dataArray = Uint8List.fromList(HEX.decode(encPrivateKey));
//print("** dataArrayhex : " + encPrivateKey);
if (dataArray.length < 12) {
return "";
}
final dataArray0to12 = dataArray.sublist(0, 12);
final cypherText = dataArray.sublist(12);
//print("cypher : " + HEX.encode(cypherText));
final iv = dataArray0to12;
//print("iv : " + HEX.encode(iv));
//print("aad : " + HEX.encode(aad));
cryptoKeys.KeyPair keyPair = cryptoKeys.KeyPair.symmetric(
cryptoKeys.SymmetricKey(keyValue: Uint8List.fromList(key)));
cryptoKeys.Encrypter encrypter = keyPair.privateKey
.createEncrypter(cryptoKeys.algorithms.encryption.aes.gcm);
Uint8List decrypted = encrypter.decrypt(
cryptoKeys.EncryptionResult(cypherText, initializationVector: iv));
return HEX.encode(decrypted);
} catch (e) {
return "";
}
}