Пример #1
0
        public void MustCorrectlySerializePublicKeyBlock()
        {
            var encrypted  = new MemoryStream() as Stream;
            var data       = new Dictionary <string, object>();
            var encryption = new PublicKeyParameters
            {
                InnerEncryption = new PasswordParameters {
                    Password = "******"
                },
                SymmetricEncryption = false
            };

            passwordEncryption.Setup(p => p.Encrypt(It.IsAny <Stream>(), It.IsAny <string>(), out encrypted)).Returns(SaveStatus.Success);
            publicKeyEncryption.Setup(p => p.Encrypt(It.IsAny <Stream>(), It.IsAny <X509Certificate2>(), out encrypted)).Returns(SaveStatus.Success);

            var result = sut.TrySerialize(data, encryption);

            compressor.Verify(c => c.Compress(It.IsAny <Stream>()), Times.Exactly(2));
            passwordEncryption.Verify(p => p.Encrypt(It.IsAny <Stream>(), It.Is <string>(s => s == encryption.InnerEncryption.Password), out encrypted), Times.Once);
            publicKeyEncryption.Verify(p => p.Encrypt(It.IsAny <Stream>(), It.IsAny <X509Certificate2>(), out encrypted), Times.Once);
            xmlSerializer.Verify(x => x.TrySerialize(It.Is <IDictionary <string, object> >(d => d == data), It.Is <EncryptionParameters>(e => e == null)), Times.Once);
            symmetricEncryption.VerifyNoOtherCalls();

            Assert.AreEqual(SaveStatus.Success, result.Status);
        }
Пример #2
0
        private SerializeResult SerializePublicKeyHashBlock(IDictionary <string, object> data, PublicKeyParameters parameters)
        {
            var result = SerializePublicKeyHashInnerBlock(data, parameters);

            if (result.Status == SaveStatus.Success)
            {
                var encryption = parameters.SymmetricEncryption ? symmetricEncryption : publicKeyEncryption;
                var prefix     = parameters.SymmetricEncryption ? BinaryBlock.PublicKeySymmetric : BinaryBlock.PublicKey;

                logger.Debug("Attempting to serialize public key hash block...");

                var status = encryption.Encrypt(result.Data, parameters.Certificate, out var encrypted);

                if (status == SaveStatus.Success)
                {
                    result.Data = WritePrefix(prefix, encrypted);
                }
            }

            return(result);
        }
 public IssueCertificateRequest(string subjectName, RSAParameters publicParameters)
 {
     SubjectName = subjectName;
     PublicKey   = new PublicKeyParameters(publicParameters);
 }