Exemplo n.º 1
0
    public void GivenNewIdentity_RSAParameters_Match()
    {
        const string issuer     = "*****@*****.**";
        var          documentId = new DocumentId("test/unit-tests-identity/identity1");

        RSA           rsa    = RSA.Create();
        RSAParameters source = rsa.ExportParameters(true);

        var entry = new IdentityEntry
        {
            DirectoryId = (string)documentId,
            Subject     = issuer,
            PublicKey   = rsa.ExportRSAPublicKey(),
            PrivateKey  = rsa.ExportRSAPrivateKey(),
        };

        RSAParameters result = entry.GetRsaParameters();

        source.D !.Length.Should().Be(result.D !.Length);
        source.DP !.Length.Should().Be(source.DP !.Length);
        source.DQ !.Length.Should().Be(source.DQ !.Length);
        source.Exponent !.Length.Should().Be(source.Exponent !.Length);
        source.InverseQ !.Length.Should().Be(source.InverseQ !.Length);
        source.Modulus !.Length.Should().Be(source.Modulus !.Length);
        source.P !.Length.Should().Be(source.P !.Length);
        source.Q !.Length.Should().Be(source.Q !.Length);

        Enumerable.SequenceEqual(source.D, result.D !);
        Enumerable.SequenceEqual(source.DP, result.DP !);
        Enumerable.SequenceEqual(source.Exponent, result.Exponent !);
        Enumerable.SequenceEqual(source.InverseQ, result.InverseQ !);
        Enumerable.SequenceEqual(source.Modulus, result.Modulus !);
        Enumerable.SequenceEqual(source.P, result.P !);
        Enumerable.SequenceEqual(source.Q, result.Q !);
    }
Exemplo n.º 2
0
    private RSAParameters Create(DocumentId documentId)
    {
        RSA           rsa    = RSA.Create();
        RSAParameters source = rsa.ExportParameters(true);

        var entry = new IdentityEntry
        {
            DirectoryId = (string)documentId,
            Subject     = "<subject>",
            PublicKey   = rsa.ExportRSAPublicKey(),
            PrivateKey  = rsa.ExportRSAPrivateKey(),
        };

        return(entry.GetRsaParameters());
    }