/// <summary> /// Save public key to PEM file. /// </summary> /// <param name="path">File path. </param> public virtual void Save(string path) { StringBuilder sb = new StringBuilder(); sb.Append("-----BEGIN CERTIFICATE REQUEST-----" + Environment.NewLine); sb.Append(GXCommon.ToBase64(Encoded)); sb.Append(Environment.NewLine + "-----END CERTIFICATE REQUEST-----"); File.WriteAllText(path, sb.ToString()); }
public string ToDer() { GXAsn1Sequence d = new GXAsn1Sequence(); d.Add((sbyte)CertificateVersion.Version2); d.Add(RawValue); GXAsn1Sequence d1 = new GXAsn1Sequence(); if (Scheme == Ecc.P256) { d1.Add(new GXAsn1ObjectIdentifier("1.2.840.10045.3.1.7")); } else if (Scheme == Ecc.P384) { d1.Add(new GXAsn1ObjectIdentifier("1.3.132.0.34")); } else { throw new Exception("Invalid ECC scheme."); } d.Add(d1); d.Add(new GXAsn1BitString(GetPublicKey().RawValue)); return(GXCommon.ToBase64(GXAsn1Converter.ToByteArray(d))); }
/// <summary> /// Private key in DER format. /// </summary> /// <returns>Private key as in DER string.</returns> public string ToDer() { return(GXCommon.ToBase64(Encoded)); }