private static byte[] DecryptKey(KeyStoreV3 <Pbkdf2Params> keystore, string password) { if (ReferenceEquals(keystore, null)) { throw new ArgumentNullException(nameof(keystore)); } if (password.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(password)); } var crypto = keystore.crypto; var kdfparams = crypto.kdfparams; // unsupported cipher if (crypto.cipher != CIPHER) { throw new ArgumentException("unsupported cipher"); } // unsupported prf if (kdfparams.prf != Pbkdf2Params.HMACSHA256) { throw new ArgumentException("unsupported kdfparams.prf"); } return(PbkdfCrypt.DecryptPbkdf2Sha256(password, Hex.ToByteArray(crypto.mac), HexToByteArray(crypto.cipherparams.iv), HexToByteArray(crypto.ciphertext), kdfparams.c, kdfparams.salt.ToByteArray(), kdfparams.dklen)); }
internal static PrivateKey DecryptKey(KeyStoreV3 <Pbkdf2Params> keyStore, string password) { if (string.IsNullOrEmpty(password)) { throw new KdfException(ErrorCode.BAD_ARGUMENT, "empty password"); } if (ReferenceEquals(keyStore, null)) { throw new KdfException(ErrorCode.BAD_ARGUMENT, "keyStore is null"); } var crypto = keyStore.crypto; var kdfparams = keyStore.crypto.kdfparams; // unsupported cipher if (crypto.cipher != CIPHER) { throw new KdfException(ErrorCode.UNSUPPORTED, $"unsupported cipher:{crypto.cipher}"); } // unsupported prf if (kdfparams.prf != Pbkdf2Params.HMACSHA256) { throw new KdfException(ErrorCode.UNSUPPORTED, $"unsupported kdfparams.prf:{kdfparams.prf}"); } var key = PbkdfCrypt.DecryptPbkdf2Sha256(password, crypto.mac.HexToBytes(), crypto.cipherparams.iv.HexToBytes(), crypto.ciphertext.HexToBytes(), kdfparams.c, kdfparams.salt.HexToBytes(), kdfparams.dklen); return(new PrivateKey(key)); }