public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { X509Certificate2 cert = (X509Certificate2)value; writer.WriteValue( UrlSafeBase64.EncodeBytes( cert.Export(X509ContentType.Pkcs12) ) ); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader?.Value != null && reader.Value.GetType() == typeof(string)) { X509Certificate2 cert = new X509Certificate2( UrlSafeBase64.DecodeBytes( (string)reader.Value ) ); return(cert); } else { return(null); } }
public void SeralizeCertificate() { CheckCertificate(); if (PasswordEncrypt) { if (EncryptionPassword == null) { throw new Exception("No decryption password was specified, can't encrypt the certificate"); } CertificateBase64 = UrlSafeBase64.EncodeBytes(_certificate.Export(X509ContentType.Pkcs12, EncryptionPassword)); } if (ProtectedStoragePath != null) { throw new NotImplementedException("Todo: implement OS storage"); } if (!PasswordEncrypt && ProtectedStoragePath == null) { CertificateBase64 = UrlSafeBase64.EncodeBytes(_certificate.Export(X509ContentType.Pkcs12)); } }
/// <summary> /// Loads an unencrypted cert /// </summary> private void LoadCertificate(HashProvider Provider) { if (PasswordEncrypt) { if (EncryptionPassword == null) { throw new Exception("No decryption password was specified, can't encrypt the certificate"); } _certificate = new X509Certificate2(UrlSafeBase64.DecodeBytes(CertificateBase64), EncryptionPassword); } if (ProtectedStoragePath != null) { throw new NotImplementedException("Todo: implement OS storage"); } if (!PasswordEncrypt && ProtectedStoragePath == null) { _certificate = new X509Certificate2(UrlSafeBase64.DecodeBytes(CertificateBase64)); } ComputeHash(Provider); }
public static string GetBytesB64(int ByteLength) { var b = GetBytes(ByteLength); return(UrlSafeBase64.EncodeBytes(b)); }
/// <summary> /// Copies the bytes from a b64 string to a new Hash (does not compute a hash) /// </summary> public static Hash FromB64(string Base64String, HashProvider _Provider, int SourceBytesLength) { var bytes = UrlSafeBase64.DecodeBytes(Base64String); return(FromComputedBytes(bytes, _Provider, SourceBytesLength)); }