Skip to content

Commit

Permalink
Merge pull request #1632 from lontivero/Fixes/StringCipher
Browse files Browse the repository at this point in the history
Authenticate initialization vector
  • Loading branch information
nopara73 committed Jul 2, 2019
2 parents efe8a78 + 1372cd2 commit d11db5d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions WalletWasabi/Crypto/StringCipher.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

Expand Down Expand Up @@ -56,7 +57,7 @@ public static string Encrypt(string plainText, string passPhrase)
writer.Write(iv);
using (var hmac = new HMACSHA256(key))
{
var authenticationCode = hmac.ComputeHash(cipherTextBytes);
var authenticationCode = hmac.ComputeHash(iv.Concat(cipherTextBytes).ToArray());
writer.Write(authenticationCode);
}
writer.Write(cipherTextBytes);
Expand Down Expand Up @@ -93,7 +94,7 @@ public static string Decrypt(string cipherText, string passPhrase)

using (var hmac = new HMACSHA256(key))
{
var calculatedAuthenticationCode = hmac.ComputeHash(cipher);
var calculatedAuthenticationCode = hmac.ComputeHash(iv.Concat(cipher).ToArray());
for (var i = 0; i < calculatedAuthenticationCode.Length; i++)
{
if (calculatedAuthenticationCode[i] != authenticationCode[i])
Expand Down

0 comments on commit d11db5d

Please sign in to comment.