/// <summary> Seperates the salt from the data provided </summary> public SaltedData(byte[] saltedData, Salt.Size szSalt) { byte[] salt = Check.ArraySize(new byte[(int)szSalt / 8], 8, 64); Array.Copy(saltedData, 0, salt, 0, salt.Length); _salt = new Salt(salt, false); _data = new byte[saltedData.Length - salt.Length]; Array.Copy(saltedData, salt.Length, _data, 0, _data.Length); }
/// <summary> Decrypts the bytes with the current password and salt </summary> public byte[] Decrypt(byte[] blob, Salt.Size szSaltSize) { try { using (SaltedData data = new SaltedData(blob, szSaltSize)) using (AESCryptoKey key = CreateKey(data.Salt)) return(key.Decrypt(data.GetDataBytes())); } catch (InvalidOperationException) { throw; } catch { throw CryptographicException(); } }
/// <summary> Decrypts the stream with the current password and salt </summary> public Stream Decrypt(Stream stream, Salt.Size szSaltSize) { try { Salt salt = new Salt(IOStream.Read(stream, (int)szSaltSize / 8), false); AESCryptoKey key = CreateKey(salt); return(new DisposingStream(key.Decrypt(stream)) .WithDisposeOf(key)); } catch (InvalidOperationException) { throw; } catch { throw CryptographicException(); } }