예제 #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
        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));
        }