Beispiel #1
0
 public static string DecryptUsingPrivateKey(string PrivateKey, int ModulosSize, string DataToDecrypt)
 {
     try
     {
         RSAx rsax = new RSAx(PrivateKey, ModulosSize);
         rsax.RSAxHashAlgorithm = RSAxParameters.RSAxHashAlgorithm.SHA512;// ha_types[comboBox_OAEP_Hash.SelectedIndex];
         byte[] PT = rsax.Decrypt(Convert.FromBase64String(DataToDecrypt), true, false);
         return(Encoding.UTF8.GetString(PT));
     }
     catch (System.Exception ex)
     {
         throw new CryptographicException("Exception while Decryption: " + ex.Message);
     }
 }
Beispiel #2
0
 public static string EncryptUsingPublicKey(string PublicKey, int ModulosSize, string DataToEncrypt)
 {
     try
     {
         RSAx rsax = new RSAx(PublicKey, ModulosSize);
         rsax.RSAxHashAlgorithm = RSAxParameters.RSAxHashAlgorithm.SHA512;// ha_types[comboBox_OAEP_Hash.SelectedIndex];
         byte[] CT = rsax.Encrypt(Encoding.UTF8.GetBytes(DataToEncrypt), false, false);
         return(Convert.ToBase64String(CT));
     }
     catch (System.Exception ex)
     {
         throw new CryptographicException("Exception while Encryption: " + ex.Message);
     }
 }