System.Security.Cryptography.RSA.Decrypt C# (CSharp) Method

Decrypt() public method

public Decrypt ( byte data, RSAEncryptionPadding padding ) : byte[]
data byte
padding RSAEncryptionPadding
return byte[]
        public virtual byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
        {
            throw DerivedClassMustOverride();
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Decrypts a string (previously encrypted with the Encrypt method)
        /// </summary>
        /// <param name="base64String">The encrypted string</param>
        /// <param name="privateKey">The private key used to decrypt the string</param>
        /// <returns>A string containing the decrypted value</returns>
        public string Decrypt(string base64String, System.Security.Cryptography.RSAParameters privateKey)
        {
            string result = null;

            try
            {
                _rsa.ImportParameters(privateKey);
                int base64BlockSize = (256 % 3 != 0) ? ((256 / 3) * 4) + 4 : (256 / 3) * 4;
                int iterations      = base64String.Length / base64BlockSize;
                int l         = 0;
                var fullbytes = new byte[0];
                for (int i = 0; i < iterations; i++)
                {
                    byte[] encBytes = Convert.FromBase64String(base64String.Substring(base64BlockSize * i, base64BlockSize));
                    byte[] bytes    = _rsa.Decrypt(encBytes, System.Security.Cryptography.RSAEncryptionPadding.Pkcs1);
                    Array.Resize(ref fullbytes, fullbytes.Length + bytes.Length);
                    foreach (byte t in bytes)
                    {
                        fullbytes[l] = t;
                        l++;
                    }
                }
                result = fullbytes.AsString();// Encoding.UTF32.GetString(fullbytes);
            }
            catch (Exception e)
            {
                Log.e(e);
            }
            return(result);
        }
All Usage Examples Of System.Security.Cryptography.RSA::Decrypt