コード例 #1
0
ファイル: Util.cs プロジェクト: ststeiger/RedmineMailService
        // https://stackoverflow.com/questions/13806299/how-to-create-a-self-signed-certificate-using-c
        static void MakeCert()
        {
            using (System.Security.Cryptography.ECDsa ecdsa = System.Security.Cryptography.ECDsa.Create())  // generate asymmetric key pair
            {
                System.Security.Cryptography.X509Certificates.CertificateRequest req =
                    new System.Security.Cryptography.X509Certificates.CertificateRequest("cn=foobar", ecdsa
                                                                                         , System.Security.Cryptography.HashAlgorithmName.SHA512
                                                                                         );

                using (System.Security.Cryptography.X509Certificates.X509Certificate2 cert =
                           req.CreateSelfSigned(System.DateTimeOffset.Now, System.DateTimeOffset.Now.AddYears(5)
                                                ))
                {
                    // Create PFX (PKCS #12) with private key
                    System.IO.File.WriteAllBytes("d:\\mycert.pfx", cert.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Pfx));

                    // Create Base 64 encoded CER (public key only)
                    System.IO.File.WriteAllText("d:\\mycert.cer",
                                                "-----BEGIN CERTIFICATE-----\r\n"
                                                + System.Convert.ToBase64String(
                                                    cert.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Cert)
                                                    , System.Base64FormattingOptions.InsertLineBreaks
                                                    )
                                                + "\r\n-----END CERTIFICATE-----");
                } // End Using cert
            }     // End Using ecdsa
        }         // End Sub MakeCert
コード例 #2
0
        public EcdsaCertificate(X509Certificate2 certificate, X509Certificate2Collection chain)
        {
            _certificate = certificate;
            _privateKey  = _certificate.GetECDsaPrivateKey();
            var curve = _privateKey.ExportParameters(false);

            if (curve.Curve.CurveType != System.Security.Cryptography.ECCurve.ECCurveType.Named)
            {
                ExceptionHelper.ThrowException(new InvalidOperationException());
            }
            switch (curve.Curve.Oid.FriendlyName)
            {
            case "nistP256":
                _certificateType          = CertificateType.Ecdsa_secp256r1;
                _supportedSignatureScheme = SignatureScheme.ecdsa_secp256r1_sha256;
                _hashType = HashType.SHA256;
                break;

            case "nistP384":
                _certificateType          = CertificateType.Ecdsa_secp384r1;
                _supportedSignatureScheme = SignatureScheme.ecdsa_secp384r1_sha384;
                _hashType = HashType.SHA384;
                break;

            case "nistP521":
                _certificateType          = CertificateType.Ecdsa_secp521r1;
                _supportedSignatureScheme = SignatureScheme.ecdsa_secp521r1_sha512;
                _hashType = HashType.SHA512;
                break;

            default:
                ExceptionHelper.ThrowException(new InvalidOperationException());
                break;
            }
            _certificateChain = new byte[chain.Count][];
            for (var i = 0; i < chain.Count; i++)
            {
                _certificateChain[i] = chain[i].RawData;
            }
        }
コード例 #3
0
 public OracleNeoFSProtocol(Wallet wallet, ECPoint[] oracles)
 {
     byte[] key = oracles.Select(p => wallet.GetAccount(p)).Where(p => p is not null && p.HasKey && !p.Lock).FirstOrDefault().GetKey().PrivateKey;
     privateKey = key.LoadPrivateKey();
 }
コード例 #4
0
 public CertificateRequest(string subjectName, System.Security.Cryptography.ECDsa key, System.Security.Cryptography.HashAlgorithmName hashAlgorithm)
 {
 }
コード例 #5
0
 public CertificateRequest(System.Security.Cryptography.X509Certificates.X500DistinguishedName subjectName, System.Security.Cryptography.ECDsa key, System.Security.Cryptography.HashAlgorithmName hashAlgorithm)
 {
 }
コード例 #6
0
 public static System.Security.Cryptography.X509Certificates.X509SignatureGenerator CreateForECDsa(System.Security.Cryptography.ECDsa key)
 {
     throw null;
 }
コード例 #7
0
 public static System.Security.Cryptography.X509Certificates.X509Certificate2 CopyWithPrivateKey(this System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, System.Security.Cryptography.ECDsa privateKey)
 {
     throw null;
 }
コード例 #8
0
 public static byte[] Sign(byte[] content, System.Security.Cryptography.ECDsa key, System.Security.Cryptography.HashAlgorithmName hashAlgorithm, bool isDetached = false)
 {
     throw null;
 }
コード例 #9
0
 public bool Verify(System.Security.Cryptography.ECDsa key, System.ReadOnlySpan <byte> content)
 {
     throw null;
 }
コード例 #10
0
 public bool Verify(System.Security.Cryptography.ECDsa key)
 {
     throw null;
 }