コード例 #1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            X509Certificate2 cert = (X509Certificate2)value;

            writer.WriteValue(
                UrlSafeBase64.EncodeBytes(
                    cert.Export(X509ContentType.Pkcs12)
                    )
                );
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
ファイル: Cert.cs プロジェクト: JeremyOne/CryptLink
        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));
            }
        }
コード例 #4
0
ファイル: Cert.cs プロジェクト: JeremyOne/CryptLink
        /// <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);
        }
コード例 #5
0
ファイル: Utility.cs プロジェクト: JeremyOne/CryptLink
        public static string GetBytesB64(int ByteLength)
        {
            var b = GetBytes(ByteLength);

            return(UrlSafeBase64.EncodeBytes(b));
        }
コード例 #6
0
        /// <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));
        }