public void LoadCertificatePemOverridesCer() { using X509Certificate2 certificate = PemReader.LoadCertificate(PEM.AsSpan(), Encoding.UTF8.GetBytes("This is not a certificate")); Assert.AreEqual("CN=Azure SDK", certificate.Subject); Assert.IsTrue(certificate.HasPrivateKey); Assert.AreEqual(2048, certificate.PrivateKey.KeySize); }
public void LoadCertificate() { using X509Certificate2 certificate = PemReader.LoadCertificate(PEM.AsSpan()); Assert.AreEqual("CN=Azure SDK", certificate.Subject); Assert.IsTrue(certificate.HasPrivateKey); Assert.AreEqual(2048, certificate.PrivateKey.KeySize); }
public void LoadedCertificateNotDisposed() { using X509Certificate2 certificate = PemReader.LoadCertificate(PEM.AsSpan()); using RSA publicKey = certificate.GetRSAPublicKey(); using RSA privateKey = certificate.GetRSAPrivateKey(); byte[] plaintext = Encoding.UTF8.GetBytes("test"); byte[] ciphertext = publicKey.Encrypt(plaintext, RSAEncryptionPadding.Pkcs1); byte[] decrypted = privateKey.Decrypt(ciphertext, RSAEncryptionPadding.Pkcs1); Assert.AreEqual(plaintext, decrypted); }
public void ReadCertificateWithPrivateKey() { ReadOnlySpan <char> data = PEM.AsSpan(); // Expect to find the private key first. Assert.IsTrue(PemReader.TryRead(data, out PemReader.PemField field)); Assert.AreEqual("PRIVATE KEY", field.Label.ToString()); Assert.AreEqual(PrivateKeyBytes, field.FromBase64Data()); // Expect to find the certificate second. data = data.Slice(field.Start + field.Length); Assert.IsTrue(PemReader.TryRead(data, out field)); Assert.AreEqual("CERTIFICATE", field.Label.ToString()); Assert.AreEqual(CertificateBytes, field.FromBase64Data()); }