1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-06 02:23:57 +00:00

Support for encrypt-then-mac

This commit is contained in:
Kyle Spearrin
2016-12-10 22:05:52 -05:00
parent 9879f7fa0a
commit 7bc38a35e8
2 changed files with 66 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ namespace Bit.App.Models
EncryptedString = encryptedString;
}
public CipherString(string initializationVector, string cipherText)
public CipherString(string initializationVector, string cipherText, string mac = null)
{
if(string.IsNullOrWhiteSpace(initializationVector))
{
@@ -31,13 +31,32 @@ namespace Bit.App.Models
}
EncryptedString = string.Format("{0}|{1}", initializationVector, cipherText);
if(!string.IsNullOrWhiteSpace(mac))
{
EncryptedString = string.Format("{0}|{1}", EncryptedString, mac);
}
}
public string EncryptedString { get; private set; }
public string InitializationVector { get { return EncryptedString?.Split('|')[0]; } }
public string CipherText { get { return EncryptedString?.Split('|')[1]; } }
public byte[] InitializationVectorBytes { get { return Convert.FromBase64String(InitializationVector); } }
public byte[] CipherTextBytes { get { return Convert.FromBase64String(CipherText); } }
public string InitializationVector => EncryptedString?.Split('|')[0] ?? null;
public string CipherText => EncryptedString?.Split('|')[1] ?? null;
public string Mac
{
get
{
var pieces = EncryptedString?.Split('|') ?? new string[0];
if(pieces.Length > 2)
{
return pieces[2];
}
return null;
}
}
public byte[] InitializationVectorBytes => Convert.FromBase64String(InitializationVector);
public byte[] CipherTextBytes => Convert.FromBase64String(CipherText);
public byte[] MacBytes => Mac == null ? null : Convert.FromBase64String(Mac);
public string Decrypt()
{