public void Constructor_Should_SetProperties() { // Arrange // Act var obj = new RsaCertificate(parameters: ScenarioRsa.DefaultRsaParameters); var rsa = obj.CreateRsa(); var rsaParameters = rsa.ExportParameters(false); // Assert rsaParameters.Exponent.SequenceEqual(ScenarioRsa.DefaultRsaParameters.Exponent).Should().BeTrue(); rsaParameters.Modulus.SequenceEqual(ScenarioRsa.DefaultRsaParameters.Modulus).Should().BeTrue(); }
public void Create_ShouldReturn_InitializedRsaCryptoServiceProvider() { // Arrange var certificate = new RsaCertificate(ScenarioRsa1.RsaParameters); // Act var rsa = certificate.CreateRsa(); // Assert var parameters = rsa.ExportParameters(false); parameters.Exponent.SequenceEqual(ScenarioRsa1.Exponent).Should().BeTrue(); parameters.Modulus.SequenceEqual(ScenarioRsa1.Modulus).Should().BeTrue(); }
public void Constructor_Should_SetProperties() { // Arrange var signature = createRsaSignature(); // Act var obj = new RsaCertificate( parameters: ScenarioRsa.DefaultRsaParameters, signCertificateCallback: (_hash) => signature); var rsa = obj.CreateRsa(); var rsaParameters = rsa.ExportParameters(false); // Assert rsaParameters.Exponent.SequenceEqual(ScenarioRsa.DefaultRsaParameters.Exponent).Should().BeTrue(); rsaParameters.Modulus.SequenceEqual(ScenarioRsa.DefaultRsaParameters.Modulus).Should().BeTrue(); obj.Signature.Should().BeSameAs(signature); }
/// <summary> /// Converts a cryptographic RSA certificate to a serialization model instance. /// </summary> /// <param name="certificate">The cryptographic RSA certificate.</param> /// <returns>The serialization model.</returns> /// <exception cref="ArgumentNullException">Thrown, if /// <paramref name="certificate"/> is null.</exception> public static SerializationModel Convert(RsaCertificate certificate) { if (certificate == null) { throw new ArgumentNullException(nameof(certificate)); } var rsaParameters = certificate.CreateRsa().ExportParameters(false); return(new SerializationModel { Hash = System.Convert.ToBase64String(certificate.Hash.Hash.ToArray()), Parameters = new RsaSerializationModel { Exponent = System.Convert.ToBase64String(rsaParameters.Exponent), Modulus = System.Convert.ToBase64String(rsaParameters.Modulus), }, EmbeddedData = certificate.EmbeddedData == null ? null : System.Convert.ToBase64String(certificate.EmbeddedData.ToArray()), SignerCertificateHash = certificate.Signature == null ? null : System.Convert.ToBase64String(certificate.Signature.SignerCertificateHash.Hash.ToArray()), Signature = certificate.Signature == null ? null : System.Convert.ToBase64String(certificate.Signature.Signature.ToArray()), }); }