public static AsnPrivateKeyPair Decode(byte[] source, ref int pos) { AsnPrivateKeyPair instance = new AsnPrivateKeyPair(); pos++; long len = instance.GetLength(source, ref pos); instance.version = AsnInteger.Decode(source, ref pos); instance.modulus = AsnInteger.Decode(source, ref pos); instance.exponent = AsnInteger.Decode(source, ref pos); instance.privateExponent = AsnInteger.Decode(source, ref pos); instance.prime1 = AsnInteger.Decode(source, ref pos); instance.prime2 = AsnInteger.Decode(source, ref pos); instance.exp1 = AsnInteger.Decode(source, ref pos); instance.exp2 = AsnInteger.Decode(source, ref pos); instance.coefficient = AsnInteger.Decode(source, ref pos); // bring the parameters into an RSA format instance.parameters.Modulus = instance.modulus.myValue.ToByteArray(); instance.parameters.Exponent = instance.exponent.myValue.ToByteArray(); instance.parameters.D = instance.privateExponent.myValue.ToByteArray(); instance.parameters.P = instance.prime1.myValue.ToByteArray(); instance.parameters.Q = instance.prime2.myValue.ToByteArray(); instance.parameters.DP = instance.exp1.myValue.ToByteArray(); instance.parameters.DQ = instance.exp2.myValue.ToByteArray(); instance.parameters.InverseQ = instance.coefficient.myValue.ToByteArray(); 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); }
public static AsnPrivateKeyInfo Decode(byte[] source, ref int pos) { AsnPrivateKeyInfo instance = new AsnPrivateKeyInfo(); //CheckContextTag(source, ref pos); pos++; int len = instance.GetLength(source, ref pos); instance.algorithm = AsnAlgorithmIdentifier.Decode(source, ref pos); instance.publicKey = AsnBitstring.Decode(source, ref pos); // TODO: further decode publicKey into AsnKeyPair int bi = 0; instance.keys = AsnPrivateKeyPair.Decode(instance.publicKey.value, ref bi); return(instance); }
public AsnPrivateKeyInfo() { algorithm = new AsnAlgorithmIdentifier(); publicKey = new AsnBitstring(); keys = new AsnPrivateKeyPair(); }