Exemplo n.º 1
0
        private IEnumerable <byte> Decrypt(byte[] key, byte[] data)
        {
            var symmetricKey = new SymmetricKey(DecryptRSA(GetPrivateKey(), key));

            if (symmetricKey == null)
            {
                return(null);
            }

            return(symmetricKey.DecryptData(data));
        }
        public void TestKey()
        {
            Assert.AreEqual("c66c9a3d66dfa2f8b9420b0379fd1b80928d8d74501e12dd5bc453a7a9a748ab", _letmein.HexData);
            var          rawKey    = new SymmetricKey(_letmein.KeyData);
            const string msg       = "To infinity!";
            var          bytes     = Encoding.UTF8.GetBytes(msg);
            var          encrypted = _letmein.EncryptData(bytes);
            var          decrypted = _letmein.DecryptData(encrypted);

            CollectionAssert.AreEqual(bytes, decrypted);
            decrypted = rawKey.DecryptData(encrypted);
            CollectionAssert.AreEqual(bytes, decrypted);
            Assert.Throws <CryptographicException>(() => _letmeout.DecryptData(encrypted));
        }