Exemplo n.º 1
0
        public void EncryptionBouncyCastleWithNativeCertTest()
        {
            const string TestString   = "Hello World!";
            var          senderCert   = new X509Certificate2(_tempCert.Export(X509ContentType.Pkcs12), (string)null, X509KeyStorageFlags.Exportable);
            var          receiverCert = new X509Certificate2(_tempCert.Export(X509ContentType.Cert), (string)null, X509KeyStorageFlags.Exportable);
            var          encryption   = new ExtraStandard.Encryption.BouncyCastlePkcs7EncryptionHandler(senderCert, receiverCert);
            var          testData     = Encoding.UTF8.GetBytes(TestString);
            var          timestamp    = DateTime.Now;
            var          encrypted    = encryption.Encrypt(testData, timestamp);
            var          decrypted    = encryption.Decrypt(encrypted);

            Assert.Equal(TestString, Encoding.UTF8.GetString(decrypted));
        }
Exemplo n.º 2
0
        public void EncryptionBouncyCastleTest()
        {
            const string TestString   = "Hello World!";
            var          senderCert   = new Pkcs12Store(new MemoryStream(_tempCert.Export(X509ContentType.Pkcs12)), new char[0]);
            var          receiverCert = Utils.FromX509Certificate(_tempCert);
            var          encryption   = new ExtraStandard.Encryption.BouncyCastlePkcs7EncryptionHandler(senderCert, receiverCert);
            var          testData     = Encoding.UTF8.GetBytes(TestString);
            var          timestamp    = DateTime.Now;
            var          encrypted    = encryption.Encrypt(testData, timestamp);
            var          decrypted    = encryption.Decrypt(encrypted);

            Assert.Equal(TestString, Encoding.UTF8.GetString(decrypted));
        }