public RecoverableSerialForm(PkiKeyPair keyPair) { _algorithm = keyPair.Algorithm; _privateKey = keyPair.PrivateKey.Export(PkiEncodingFormat.Der); _publicKey = keyPair.PublicKey.Export(PkiEncodingFormat.Der); _kpParams = keyPair.Parameters; }
/// <summary> /// Creates a new instance of a PKI Certificate Signing Request. /// </summary> /// <param name="subjectName">The Subject Name of the Certificate Request in X509 /// directory format, e.g. <c>CN=app.example.com</c>.</param> /// <param name="keyPair">A public/private key pair.</param> /// <param name="hashAlgorithm">The hash algorithm to be used.</param> public PkiCertificateSigningRequest(string subjectName, PkiKeyPair keyPair, PkiHashAlgorithm hashAlgorithm) { SubjectName = subjectName; _keyPair = keyPair; PublicKey = _keyPair.PublicKey; HashAlgorithm = hashAlgorithm; }
// Helpful for debugging: // public object ExportEcParameters() // { // var pub = (ECPublicKeyParameters)_PublicKey.NativeKey; // var prv = (ECPrivateKeyParameters)_PrivateKey.NativeKey; // var exp = new // { // HashSize = prv.D.ToByteArrayUnsigned().Length * 8, // D = prv.D.ToByteArrayUnsigned(), // X = pub.Q.XCoord.GetEncoded(), // Y = pub.Q.YCoord.GetEncoded(), // }; // return exp; // } internal static object ExportRsJwk(PkiKeyPair keys, bool @private) { if (@private) { throw new NotImplementedException(); } var pub = (RsaKeyParameters)keys.PublicKey.NativeKey; return(new { // As per RFC 7638 Section 3, these are the *required* elements of the // JWK and are sorted in lexicographic order to produce a canonical form e = Base64Tool.Instance.UrlEncode(pub.Exponent.ToByteArray()), kty = "RSA", // https://tools.ietf.org/html/rfc7518#section-6.3 n = Base64Tool.Instance.UrlEncode(pub.Modulus.ToByteArray()), }); }
internal static object ExportEcJwk(int bits, PkiKeyPair keys, bool @private) { if (@private) { throw new NotImplementedException(); } var pub = (ECPublicKeyParameters)keys.PublicKey.NativeKey; return(new { // As per RFC 7638 Section 3, these are the *required* elements of the // JWK and are sorted in lexicographic order to produce a canonical form crv = $"P-{bits}", kty = "EC", // https://tools.ietf.org/html/rfc7518#section-6.2 x = Base64Tool.Instance.UrlEncode(pub.Q.XCoord.GetEncoded()), y = Base64Tool.Instance.UrlEncode(pub.Q.YCoord.GetEncoded()), }); }