예제 #1
0
 /// <summary>
 /// Encrypts the input string using the specified encoding and padding mode.
 /// </summary>
 /// <param name="rsa">The RSA algorithm instance.</param>
 /// <param name="data">The string data to encrypt.</param>
 /// <param name="encoding">The encoding.</param>
 /// <param name="padding">The padding mode.</param>
 /// <returns></returns>
 public static byte[] Encrypt(this RSA rsa, SecureString data, RSAEncryptionPadding padding, Encoding encoding = null)
 {
     if (data == null)
     {
         return(null);
     }
     if (rsa == null)
     {
         throw new ArgumentNullException(nameof(rsa), "rsa should not be null.");
     }
     return(rsa.Encrypt((encoding ?? Encoding.UTF8).GetBytes(SecureStringExtensions.ToUnsecureString(data)), padding));
 }
예제 #2
0
 /// <summary>
 /// Determines whether the specified object is equal to the current object.
 /// </summary>
 /// <param name="other">The object to compare with the current object.</param>
 /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
 public override bool Equals(object other)
 {
     if (other is null)
     {
         return(false);
     }
     if (other is Parser p)
     {
         return(Equals(p));
     }
     if (other is string s)
     {
         return(Equals(s));
     }
     if (other is SecureString ss)
     {
         return(Equals(SecureStringExtensions.ToUnsecureString(ss)));
     }
     if (other is StringBuilder sb)
     {
         return(Equals(sb.ToString()));
     }
     return(false);
 }
예제 #3
0
 /// <summary>
 /// Gets the encrypted text by private key.
 /// </summary>
 /// <param name="text">The string to encrypt.</param>
 /// <param name="ignoreFormatIfNoCrypto">true if ignore format when no crypto set; otherwise, false.</param>
 /// <param name="padding">The optional padding mode for decryption.</param>
 /// <returns>The Base64 string with secret encrypted.</returns>
 public string EncryptText(SecureString text, bool ignoreFormatIfNoCrypto = false, RSAEncryptionPadding padding = null)
 {
     return(EncryptText(SecureStringExtensions.ToUnsecureString(text), ignoreFormatIfNoCrypto, padding));
 }