BraintreeEncryption.Library.BouncyCastle.Crypto.Encodings.Pkcs1Encoding.Init C# (CSharp) Method

Init() public method

public Init ( bool forEncryption, ICipherParameters parameters ) : void
forEncryption bool
parameters ICipherParameters
return void
        public void Init(
			bool				forEncryption,
			ICipherParameters	parameters)
        {
            AsymmetricKeyParameter kParam;
            if (parameters is ParametersWithRandom)
            {
                ParametersWithRandom rParam = (ParametersWithRandom)parameters;

                this.random = rParam.Random;
                kParam = (AsymmetricKeyParameter)rParam.Parameters;
            }
            else
            {
                this.random = new SecureRandom();
                kParam = (AsymmetricKeyParameter)parameters;
            }

            engine.Init(forEncryption, parameters);

            this.forPrivateKey = kParam.IsPrivate;
            this.forEncryption = forEncryption;
        }

Usage Example

 public string Encrypt(byte[] dataToEncrypt)
 {
     var rsaKeyParameters = GetRsaKeyParameters();
     var rsaEngine = new Pkcs1Encoding(new RsaEngine());
     rsaEngine.Init(true, rsaKeyParameters);
     var encodedDataToEncrypt = new UTF8Encoding().GetBytes(Convert.ToBase64String(dataToEncrypt));
     return Convert.ToBase64String(rsaEngine.ProcessBlock(encodedDataToEncrypt, 0, encodedDataToEncrypt.Length));
 }
All Usage Examples Of BraintreeEncryption.Library.BouncyCastle.Crypto.Encodings.Pkcs1Encoding::Init