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); } }
/// <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); }
/// <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)); }