Esempio n. 1
0
        public void LoadFromCertificateFile_Should_LoadCertificate_When_FileIsPasswordProtected()
        {
            // Arrange
            var cert = $"{_assemblyPath}RsaEncrypt.pfx";

            // Act
            var publicKey = RsaPublicKey.LoadFromCertificateFile(cert, "password");

            // Assert
            Assert.NotNull(publicKey);
        }
Esempio n. 2
0
        public void Decrypt_Should_ReturnExpectedResult_When_KeyIsStoredInCertificate()
        {
            // Arrange
            var cert = $"{_assemblyPath}RsaEncrypt";

            var publicKey  = RsaPublicKey.LoadFromCertificateFile(cert + ".cer");
            var privateKey = RsaPrivateKey.LoadFromCertificateFile(cert + ".pfx", "password");

            var e1 = new RsaEncryption();
            var e2 = new RsaEncryption();

            // Act
            var encryptedData = e1.Encrypt(new EncryptionData(Secret), publicKey);
            var decryptedData = e2.Decrypt(encryptedData, privateKey);

            // Assert
            Assert.Equal(decryptedData.Text, Secret);
        }
Esempio n. 3
0
        public ASymmetricEncryptionTests()
        {
            var fullPath      = Assembly.GetAssembly(typeof(ASymmetricEncryptionTests)).Location;
            var pathDirectory = Path.GetDirectoryName(fullPath);
            var separator     = Path.DirectorySeparatorChar;

            _assemblyPath = $"{pathDirectory}{separator}";

            _targetString = "Did you know that some of the most famous inventions would "
                            + "never have been made if the inventors had stopped at their "
                            + "first failure? For instance, Thomas Edison, inventor of "
                            + "the light bulb had 1,000 failed attempts at creating one "
                            + "light bulb that worked properly. - Vee Freir";

            _targetData = new EncryptionData(_targetString);

            _privateKey = RsaPrivateKey.LoadFromCertificateFile(
                $"{_assemblyPath}ASymmetricEncryption.pfx",
                "password");

            _publicKey = RsaPublicKey.LoadFromCertificateFile(
                $"{_assemblyPath}ASymmetricEncryption.pfx",
                "password");
        }
Esempio n. 4
0
 public void LoadFromCertificateFile_Should_ThrowException_When_PublicKeyFileWithPasswordDoesNotExists()
 {
     // Assert
     Assert.Throws <ArgumentException>(()
                                       => RsaPublicKey.LoadFromCertificateFile($"{_assemblyPath}nonexist.cer", "password"));
 }