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