Пример #1
0
        public static RSAKeyEncoded KeyEncode(RSAParameters key, ByteEncodeMethod byteEncodeMethod)
        {
            RSAKeyEncoded rsakeyEncoded = new RSAKeyEncoded(byteEncodeMethod);

            rsakeyEncoded.FromRSAParameters(key);
            return(rsakeyEncoded);
        }
Пример #2
0
 public void FromRSAParameters(RSAParameters param, ByteEncodeMethod byteEncodeMethod)
 {
     if (param.D != null)
     {
         this.D = ByteArrayEncoder.Encode(param.D, byteEncodeMethod);
     }
     if (param.DP != null)
     {
         this.DP = ByteArrayEncoder.Encode(param.DP, byteEncodeMethod);
     }
     if (param.DQ != null)
     {
         this.DQ = ByteArrayEncoder.Encode(param.DQ, byteEncodeMethod);
     }
     if (param.Exponent != null)
     {
         this.Exponent = ByteArrayEncoder.Encode(param.Exponent, byteEncodeMethod);
     }
     if (param.InverseQ != null)
     {
         this.InverseQ = ByteArrayEncoder.Encode(param.InverseQ, byteEncodeMethod);
     }
     if (param.Modulus != null)
     {
         this.Modulus = ByteArrayEncoder.Encode(param.Modulus, byteEncodeMethod);
     }
     if (param.P != null)
     {
         this.P = ByteArrayEncoder.Encode(param.P, byteEncodeMethod);
     }
     if (param.Q != null)
     {
         this.Q = ByteArrayEncoder.Encode(param.Q, byteEncodeMethod);
     }
 }
Пример #3
0
        public static string Decrypt(RSAKeyEncoded encodedKey, string encryptedText, ByteEncodeMethod ByteEncode, Encoding TextEncode)
        {
            RSAParameters key = encodedKey.ToRSAParameters();

            byte[] encryptedText2 = ByteArrayEncoder.Decode(encryptedText, ByteEncode);
            byte[] bytes          = RSASimpleWrapper.Decrypt(key, encryptedText2);
            return(TextEncode.GetString(bytes));
        }
Пример #4
0
        public static string Encrypt(RSAKeyEncoded encodedKey, string plainText, ByteEncodeMethod ByteEncode, Encoding TextEncode)
        {
            RSAParameters key = encodedKey.ToRSAParameters();

            byte[] bytes     = TextEncode.GetBytes(plainText);
            byte[] byteArray = RSASimpleWrapper.Encrypt(key, bytes);
            return(ByteArrayEncoder.Encode(byteArray, ByteEncode));
        }
Пример #5
0
 public RSAKeyEncoded(ByteEncodeMethod encodeMethod)
 {
     this.D             = string.Empty;
     this.DP            = string.Empty;
     this.DQ            = string.Empty;
     this.Exponent      = string.Empty;
     this.InverseQ      = string.Empty;
     this.Modulus       = string.Empty;
     this.P             = string.Empty;
     this.Q             = string.Empty;
     this._encodeMethod = encodeMethod;
 }
Пример #6
0
        public RSAParameters ToRSAParameters(ByteEncodeMethod byteEncodeMethod)
        {
            RSAParameters result = default(RSAParameters);

            if (!string.IsNullOrEmpty(this.D))
            {
                result.D = ByteArrayEncoder.Decode(this.D, byteEncodeMethod);
            }
            if (!string.IsNullOrEmpty(this.DP))
            {
                result.DP = ByteArrayEncoder.Decode(this.DP, byteEncodeMethod);
            }
            if (!string.IsNullOrEmpty(this.DQ))
            {
                result.DQ = ByteArrayEncoder.Decode(this.DQ, byteEncodeMethod);
            }
            if (!string.IsNullOrEmpty(this.Exponent))
            {
                result.Exponent = ByteArrayEncoder.Decode(this.Exponent, byteEncodeMethod);
            }
            if (!string.IsNullOrEmpty(this.InverseQ))
            {
                result.InverseQ = ByteArrayEncoder.Decode(this.InverseQ, byteEncodeMethod);
            }
            if (!string.IsNullOrEmpty(this.Modulus))
            {
                result.Modulus = ByteArrayEncoder.Decode(this.Modulus, byteEncodeMethod);
            }
            if (!string.IsNullOrEmpty(this.P))
            {
                result.P = ByteArrayEncoder.Decode(this.P, byteEncodeMethod);
            }
            if (!string.IsNullOrEmpty(this.Q))
            {
                result.Q = ByteArrayEncoder.Decode(this.Q, byteEncodeMethod);
            }
            return(result);
        }
Пример #7
0
        public static byte[] Decode(string Encoded, ByteEncodeMethod Method)
        {
            byte[] result;
            switch (Method)
            {
            case ByteEncodeMethod.Hex:
                result = ByteArrayEncoder.DecodeHex(Encoded);
                break;

            case ByteEncodeMethod.Base64:
                result = ByteArrayEncoder.DecodeBase64(Encoded);
                break;

            case ByteEncodeMethod.Base64UrlSafe:
                result = ByteArrayEncoder.DecodeBase64UrlSafe(Encoded);
                break;

            default:
                result = null;
                break;
            }
            return(result);
        }
Пример #8
0
        public static string Encode(byte[] ByteArray, ByteEncodeMethod Method)
        {
            string result = string.Empty;

            switch (Method)
            {
            case ByteEncodeMethod.Hex:
                result = ByteArrayEncoder.EncodeHex(ByteArray);
                break;

            case ByteEncodeMethod.Base64:
                result = ByteArrayEncoder.EncodeBase64(ByteArray);
                break;

            case ByteEncodeMethod.Base64UrlSafe:
                result = ByteArrayEncoder.EncodeBase64UrlSafe(ByteArray);
                break;

            default:
                result = string.Empty;
                break;
            }
            return(result);
        }
Пример #9
0
 public static RSAParameters KeyDecode(RSAKeyEncoded encoded, ByteEncodeMethod byteEncodeMethod)
 {
     return(encoded.ToRSAParameters(byteEncodeMethod));
 }
Пример #10
0
 public static string Decrypt(string Key, string Iv, CipherMode Mode, PaddingMode Padding, string Encrypted, ByteEncodeMethod ByteEncode, Encoding TextEncode)
 {
     byte[] encrypted = ByteArrayEncoder.Decode(Encrypted, ByteEncode);
     byte[] key       = ByteArrayEncoder.Decode(Key, ByteEncode);
     byte[] iv        = ByteArrayEncoder.Decode(Iv, ByteEncode);
     byte[] bytes     = AesWrapper.Decrypt(key, iv, Mode, Padding, encrypted);
     return(TextEncode.GetString(bytes));
 }
Пример #11
0
 public static string Encrypt(string Key, string Iv, CipherMode Mode, PaddingMode Padding, string Plain, ByteEncodeMethod ByteEncode, Encoding TextEncode)
 {
     byte[] bytes     = TextEncode.GetBytes(Plain);
     byte[] key       = ByteArrayEncoder.Decode(Key, ByteEncode);
     byte[] iv        = ByteArrayEncoder.Decode(Iv, ByteEncode);
     byte[] byteArray = AesWrapper.Encrypt(key, iv, Mode, Padding, bytes);
     return(ByteArrayEncoder.Encode(byteArray, ByteEncode));
 }