public void TestCreate509AuthorityKeyIdentifierExtension2() { var authority = "CN=TestAuthority"; var keyId = "32362340932423"; var serial = new byte[20]; var rand = new Random(); rand.NextBytes(serial); serial[0] = 0; serial[1] = 0; serial[2] = 0; var serialNumber = new SerialNumber(serial); using (var rsa = RSA.Create()) { var request = rsa.ToKey().CreateCertificateRequest( new X500DistinguishedName("CN=test"), SignatureType.PS256, new X509AuthorityKeyIdentifierExtension(authority, serialNumber, keyId) .YieldReturn()); var cert = request.Create(new X500DistinguishedName("CN=test"), X509SignatureGenerator.CreateForRSA(rsa, RSASignaturePadding.Pkcs1), DateTime.UtcNow, DateTime.UtcNow + TimeSpan.FromDays(1), serialNumber.Value); var aki = cert.GetAuthorityKeyIdentifierExtension(); Assert.Equal(serialNumber, aki.SerialNumber); Assert.Equal(serialNumber.ToString(), cert.SerialNumber); Assert.Equal(aki.SerialNumber, SerialNumber.Parse(cert.SerialNumber)); } }
public void ConvertToStringAndParseSize(long value) { var serial1 = new SerialNumber(value); var serial2 = SerialNumber.Parse(serial1.ToString()); Assert.Equal(serial1, serial2); }