Exemple #1
0
        /// <summary>
        /// Method to decrypt with the RSA technique, with the static RSA info
        /// </summary>
        /// <param name="input">the byte array to decrypt</param>
        /// <returns>decrypted string data</returns>
        public static string DecryptRSA(byte[] input)
        {
            LogManager.Instance.Log().Debug("Calling Encrypt RSA with default crypt info");
            if (RSA_cryptInfo == null)
            {
                LogManager.Instance.Log().Debug("Creating a new static instance of RSA Crypt info");
                RSA_cryptInfo = new RSACryptInfo(512);
            }

            return(DecryptRSA(input, RSA_cryptInfo));
        }
Exemple #2
0
        /// <summary>
        /// Method to decrypt with the RSA technique, with a supplied RSA info
        /// </summary>
        /// <param name="input">the byte array to decrypt</param>
        /// <param name="cryptInfo">the RSA crypt info</param>
        /// <returns>decrypted string data</returns>
        public static string DecryptRSA(byte[] input, RSACryptInfo cryptInfo)
        {
            LogManager.Instance.Log().Debug("Calling Decrypt RSA");

            try
            {
                RSACryptoServiceProvider csp = new RSACryptoServiceProvider(cryptInfo.keySize);
                csp.ImportParameters(cryptInfo.privateKey);
                return(new ASCIIEncoding().GetString(csp.Decrypt(input, false)).Trim('\0'));
            }
            catch (CryptographicException e)
            {
                LogManager.Instance.Log().Fatal(string.Format("Cryptographic failure occured: {0}", e.Message));
                return(null);
            }
        }