internal static byte[] EncodeX509PublicKey(System.Security.Cryptography.X509Certificates.PublicKey public_key, bool ec_flag) { if (public_key == null) { return(null); } TestKey(public_key.Oid.Value, ec_flag); DerSequence algorithm = new DerSequence(new DerObjectIdentifier(public_key.Oid.Value)); Asn1StreamParser asp = new Asn1StreamParser(public_key.EncodedParameters.RawData); IAsn1Convertible ro; while ((ro = asp.ReadObject()) != null) { algorithm.AddObject(ro.ToAsn1Object()); } return(new DerSequence(algorithm, new DerBitString(public_key.EncodedKeyValue.RawData)).GetEncoded()); }
// Extension method to the .NET PublicKey class public static string Format(this System.Security.Cryptography.X509Certificates.PublicKey public_key) { Asn1Sequence inner = Asn1Sequence.GetInstance(Asn1Object.FromByteArray(EncodeX509PublicKey(public_key))); byte[] raw_key = DerBitString.GetInstance(inner[1]).GetBytes(); Asn1Sequence algorithm = Asn1Sequence.GetInstance(inner[0]); if (DerObjectIdentifier.GetInstance(algorithm[0]).Id == RSA_PUBLIC_KEY) { Asn1Sequence rsa_values = Asn1Sequence.GetInstance(Asn1Object.FromByteArray(raw_key)); return("RSA Public Key (" + Hex.ToHexString(DerInteger.GetInstance(rsa_values[0]).Value.ToByteArrayUnsigned()) + ", " + DerInteger.GetInstance(rsa_values[1]).ToString() + ")"); } else { return("EC Public Key (" + DerObjectIdentifier.GetInstance(algorithm[1]).Id + ", " + Hex.ToHexString(raw_key) + ")"); } }
public override void Reset() { this.m_version = 0; this.m_notBefore = DateTime.MinValue; this.m_notAfter = DateTime.MinValue; this.m_privateKey = null; this.m_publicKey = null; this.m_extensions = null; this.m_signatureAlgorithm = null; this.m_subjectName = null; this.m_issuerName = null; if (!this.m_safeCertContext.IsInvalid) { this.m_safeCertContext.Dispose(); this.m_safeCertContext = System.Security.Cryptography.SafeCertContextHandle.InvalidHandle; } base.Reset(); }
public X509SubjectKeyIdentifierExtension(System.Security.Cryptography.X509Certificates.PublicKey key, System.Security.Cryptography.X509Certificates.X509SubjectKeyIdentifierHashAlgorithm algorithm, bool critical) { }
public CertificateRequest(System.Security.Cryptography.X509Certificates.X500DistinguishedName subjectName, System.Security.Cryptography.X509Certificates.PublicKey publicKey, System.Security.Cryptography.HashAlgorithmName hashAlgorithm) { }
///////////////////////////////////////////// some information form stackoverflow.com :) ////// // // Encryption is where anyone may write a message, but only the private key holder may read it. // Signing is where anyone may read a message, but only the private key holder may write it. // // When you call Decrypt, the RSACryptoServiceProvider is looking for encryption, that is, // public write private read. Thus it looks for the private key. // You want to use the SignData and VerifyData functions to sign the payload so that people can't write it. // ////// ////// // // to send a message, call gpg, encrypt with the public key of the recipient, // and while you're at it sign with the private key of the sender. // When receiving a message, check the signature against the purported sender's public key, // and decrypt with the private key of the receiver. // In other words, send with gpg --sign --encrypt -r NAME_OF_RECIPIENT and receive with gpg --verify followed by gpg --decrypt. // ////// public static RSAParameters keyToRSAKey(System.Security.Cryptography.X509Certificates.PublicKey publicKey) { return(((RSACryptoServiceProvider)publicKey.Key).ExportParameters(false)); }
public static byte[] EncodeX509PublicKey(System.Security.Cryptography.X509Certificates.PublicKey public_key) { return(EncodeX509PublicKey(public_key, false)); }
// Extension method to the .NET PublicKey class public static bool IsRSA(this System.Security.Cryptography.X509Certificates.PublicKey public_key) { return(public_key.Oid.Value == Conversions.RSA_PUBLIC_KEY); }
// Extension method to the .NET PublicKey class public static byte[] X509Encoding(this System.Security.Cryptography.X509Certificates.PublicKey public_key) { return(EncodeX509PublicKey(public_key)); }
public static Org.BouncyCastle.Crypto.AsymmetricKeyParameter BCPublicKey(this System.Security.Cryptography.X509Certificates.PublicKey public_key) { Org.BouncyCastle.Asn1.X509.SubjectPublicKeyInfo subinfo = Org.BouncyCastle.Asn1.X509.SubjectPublicKeyInfo.GetInstance(Org.BouncyCastle.Asn1.Asn1Sequence.GetInstance(Org.BouncyCastle.Asn1.Asn1Object.FromByteArray(Conversions.EncodeX509PublicKey(public_key)))); return(Org.BouncyCastle.Security.PublicKeyFactory.CreateKey(subinfo)); }
public override string ToString(bool verbose) { if (!verbose || this.m_safeCertContext.IsInvalid) { return(this.ToString()); } StringBuilder sb = new StringBuilder(); sb.Append("[Version]" + Environment.NewLine + " "); sb.Append("V" + this.Version); sb.Append(Environment.NewLine + Environment.NewLine + "[Subject]" + Environment.NewLine + " "); sb.Append(this.SubjectName.Name); string nameInfo = this.GetNameInfo(X509NameType.SimpleName, false); if (nameInfo.Length > 0) { sb.Append(Environment.NewLine + " Simple Name: "); sb.Append(nameInfo); } string str2 = this.GetNameInfo(X509NameType.EmailName, false); if (str2.Length > 0) { sb.Append(Environment.NewLine + " Email Name: "); sb.Append(str2); } string str3 = this.GetNameInfo(X509NameType.UpnName, false); if (str3.Length > 0) { sb.Append(Environment.NewLine + " UPN Name: "); sb.Append(str3); } string str4 = this.GetNameInfo(X509NameType.DnsName, false); if (str4.Length > 0) { sb.Append(Environment.NewLine + " DNS Name: "); sb.Append(str4); } sb.Append(Environment.NewLine + Environment.NewLine + "[Issuer]" + Environment.NewLine + " "); sb.Append(this.IssuerName.Name); nameInfo = this.GetNameInfo(X509NameType.SimpleName, true); if (nameInfo.Length > 0) { sb.Append(Environment.NewLine + " Simple Name: "); sb.Append(nameInfo); } str2 = this.GetNameInfo(X509NameType.EmailName, true); if (str2.Length > 0) { sb.Append(Environment.NewLine + " Email Name: "); sb.Append(str2); } str3 = this.GetNameInfo(X509NameType.UpnName, true); if (str3.Length > 0) { sb.Append(Environment.NewLine + " UPN Name: "); sb.Append(str3); } str4 = this.GetNameInfo(X509NameType.DnsName, true); if (str4.Length > 0) { sb.Append(Environment.NewLine + " DNS Name: "); sb.Append(str4); } sb.Append(Environment.NewLine + Environment.NewLine + "[Serial Number]" + Environment.NewLine + " "); sb.Append(this.SerialNumber); sb.Append(Environment.NewLine + Environment.NewLine + "[Not Before]" + Environment.NewLine + " "); sb.Append(X509Certificate.FormatDate(this.NotBefore)); sb.Append(Environment.NewLine + Environment.NewLine + "[Not After]" + Environment.NewLine + " "); sb.Append(X509Certificate.FormatDate(this.NotAfter)); sb.Append(Environment.NewLine + Environment.NewLine + "[Thumbprint]" + Environment.NewLine + " "); sb.Append(this.Thumbprint); sb.Append(Environment.NewLine + Environment.NewLine + "[Signature Algorithm]" + Environment.NewLine + " "); sb.Append(this.SignatureAlgorithm.FriendlyName + "(" + this.SignatureAlgorithm.Value + ")"); System.Security.Cryptography.X509Certificates.PublicKey publicKey = this.PublicKey; sb.Append(Environment.NewLine + Environment.NewLine + "[Public Key]" + Environment.NewLine + " Algorithm: "); sb.Append(publicKey.Oid.FriendlyName); sb.Append(Environment.NewLine + " Length: "); sb.Append(publicKey.Key.KeySize); sb.Append(Environment.NewLine + " Key Blob: "); sb.Append(publicKey.EncodedKeyValue.Format(true)); sb.Append(Environment.NewLine + " Parameters: "); sb.Append(publicKey.EncodedParameters.Format(true)); this.AppendPrivateKeyInfo(sb); X509ExtensionCollection extensions = this.Extensions; if (extensions.Count > 0) { sb.Append(Environment.NewLine + Environment.NewLine + "[Extensions]"); X509ExtensionEnumerator enumerator = extensions.GetEnumerator(); while (enumerator.MoveNext()) { X509Extension current = enumerator.Current; sb.Append(Environment.NewLine + "* " + current.Oid.FriendlyName + "(" + current.Oid.Value + "):" + Environment.NewLine + " " + current.Format(true)); } } sb.Append(Environment.NewLine); return(sb.ToString()); }
public override void Reset() { this.m_version = 0; this.m_notBefore = DateTime.MinValue; this.m_notAfter = DateTime.MinValue; this.m_privateKey = null; this.m_publicKey = null; this.m_extensions = null; this.m_signatureAlgorithm = null; this.m_subjectName = null; this.m_issuerName = null; if (!this.m_safeCertContext.IsInvalid) { this.m_safeCertContext.Dispose(); this.m_safeCertContext = System.Security.Cryptography.SafeCertContextHandle.InvalidHandle; } base.Reset(); }