public AccountDescriptor Authenticate(ulong accountId, string password) { Account account = _dataAccessService.GetAccount(accountId); if (account == null) { throw new AccountNotFoundException(accountId); } AccountDescriptor accountDescriptor = null; if (account.AccountType == AccountType.User) { accountDescriptor = AuthenticateUtxoAccount(new AuthenticationInput { Password = password, Account = account }); } else { accountDescriptor = AuthenticateStateAccount(new AuthenticationInput { Password = password, Account = account }); } return(accountDescriptor); }
private Tuple <byte[], byte[]> DecryptUtxoKeys(Account account, string passphrase) { byte[] publicSpendKeyBuf, publicViewKeyBuf; Tuple <byte[], byte[]> keys = GetSecretKeys(account, passphrase); publicSpendKeyBuf = ConfidentialAssetsHelper.GetPublicKey(keys.Item1); publicViewKeyBuf = ConfidentialAssetsHelper.GetPublicKey(keys.Item2); bool res = publicSpendKeyBuf.Equals32(account.PublicSpendKey) && publicViewKeyBuf.Equals32(account.PublicViewKey); return(res ? keys : null); }
private Tuple <byte[], byte[]> GetSecretKeys(Account account, string passphrase) { using (var aes = Aes.Create()) { aes.IV = _dataAccessService.GetAesInitializationVector(); byte[] passphraseBytes = Encoding.ASCII.GetBytes(passphrase); aes.Key = SHA256.Create().ComputeHash(passphraseBytes); aes.Padding = PaddingMode.None; byte[] secretSpendKey = aes.CreateDecryptor().TransformFinalBlock(account.SecretSpendKey, 0, account.SecretSpendKey.Length); byte[] secretViewKey = aes.CreateDecryptor().TransformFinalBlock(account.SecretViewKey, 0, account.SecretViewKey.Length); return(new Tuple <byte[], byte[]>(secretSpendKey, secretViewKey)); } }
private byte[] DecryptStateKeys(Account account, string passphrase) { byte[] secretSpendKey; using (var aes = Aes.Create()) { aes.IV = _dataAccessService.GetAesInitializationVector(); byte[] passphraseBytes = Encoding.ASCII.GetBytes(passphrase); aes.Key = SHA256.Create().ComputeHash(passphraseBytes); aes.Padding = PaddingMode.None; secretSpendKey = aes.CreateDecryptor().TransformFinalBlock(account.SecretSpendKey, 0, account.SecretSpendKey.Length); } byte[] publicSpendKeyBuf = ConfidentialAssetsHelper.GetPublicKey(Ed25519.SecretKeyFromSeed(secretSpendKey)); bool res = publicSpendKeyBuf.Equals32(account.PublicSpendKey); return(res ? secretSpendKey : null); }