public static AsnCertificate Decode(byte[] source, ref int pos) { AsnCertificate instance = new AsnCertificate(); //instance.CheckContextTag(source, ref pos); pos++; long len = instance.GetLength(source, ref pos); instance.elements.Add(AsnToBeSignedCertificate.Decode(source, ref pos)); instance.elements.Add(AsnAlgorithmIdentifier.Decode(source, ref pos)); instance.elements.Add(AsnBitstring.Decode(source, ref pos)); return(instance); }
// sign the TBS certificate with the CA key or intermediate key, returns the signed certificate ready for deployment public AsnCertificate Sign(AsnPrivateKeyPair key) { AsnCertificate cert = new AsnCertificate(this); Encode(); RSA rsa = RSA.Create(); rsa.ImportParameters(key.parameters); cert.signatureAlgorithm.algorithmID.value = new Oid("1.2.840.113549.1.1.11"); // sha256withRSA cert.signature = new AsnBitstring(rsa.SignData(derValue, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1)); return(cert); }