public void PackingAndUnpackingResultsInOriginal() { CryptoHeader header = new CryptoHeader { PackageName = "MyAppName", AlgorithmName = "Twofish", KdfName = "PBKDF2", Cost = "10", Nonce = CommonMocksAndStubs.FilledByteArray(8, 66), Salt = CommonMocksAndStubs.FilledByteArray(8, 77), Compression = "gzip", }; byte[] cipher = CommonMocksAndStubs.FilledByteArray(16, 88); byte[] packedHeader = CryptoHeaderPacker.PackHeaderAndCypher(header, cipher); CryptoHeaderPacker.UnpackHeaderAndCipher(packedHeader, "MyAppName", out CryptoHeader unpackedHeader, out byte[] unpackedCipher); Assert.AreEqual(header.PackageName, unpackedHeader.PackageName); Assert.AreEqual(header.AlgorithmName, unpackedHeader.AlgorithmName); Assert.AreEqual(header.KdfName, unpackedHeader.KdfName); Assert.AreEqual(header.Cost, unpackedHeader.Cost); Assert.AreEqual(header.Nonce, unpackedHeader.Nonce); Assert.AreEqual(header.Salt, unpackedHeader.Salt); Assert.AreEqual(cipher, unpackedCipher); Assert.AreEqual(header.Compression, unpackedHeader.Compression); }
public void PackingAndUnpackingWorksWithKeyOnly() { // If the encryption is started with a key instead of a password, there are not all parametes set. CryptoHeader header = new CryptoHeader { PackageName = "MyAppName", AlgorithmName = "Twofish", KdfName = null, Cost = null, Nonce = CommonMocksAndStubs.FilledByteArray(8, 66), Salt = null, Compression = "gzip", }; byte[] cipher = CommonMocksAndStubs.FilledByteArray(16, 88); byte[] packedHeader = CryptoHeaderPacker.PackHeaderAndCypher(header, cipher); CryptoHeaderPacker.UnpackHeaderAndCipher(packedHeader, "MyAppName", out CryptoHeader unpackedHeader, out byte[] unpackedCipher); Assert.AreEqual(header.PackageName, unpackedHeader.PackageName); Assert.AreEqual(header.AlgorithmName, unpackedHeader.AlgorithmName); Assert.AreEqual(header.KdfName, unpackedHeader.KdfName); Assert.AreEqual(header.Cost, unpackedHeader.Cost); Assert.AreEqual(header.Nonce, unpackedHeader.Nonce); Assert.AreEqual(header.Salt, unpackedHeader.Salt); Assert.AreEqual(cipher, unpackedCipher); Assert.AreEqual(header.Compression, unpackedHeader.Compression); }