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));
        }
Ejemplo n.º 2
0
        private byte[][] Encrypt(byte[] data)
        {
            try {
                var symmetricKey = new SymmetricKey();
                var encryptedKey = EncryptRSA(GetPublicKey(), symmetricKey.KeyData);
                if (encryptedKey == null)
                {
                    return(null);
                }

                var encryptedData = new byte[2][];
                encryptedData[0] = encryptedKey;
                encryptedData[1] = symmetricKey.EncryptData(data);
                return(encryptedData);
            } catch (Exception e) {
                Log.To.NoDomain.E(Tag, "Error during encryption", e);
                return(null);
            }
        }