Org.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

		internal string Decrypt(string cryptText, string encryptionKey, bool isPrivate)
		{
			RsaKeyParameters key;
			byte[] data = null;
			List<byte> output = new List<byte>();
			string result = null;

			try
			{
				if (isPrivate)
					key = RsaPrivateStringToRsaKey(encryptionKey);
				else
					key = RsaPublicStringToRsaKey(encryptionKey);

				data = Hex.Decode(cryptText);

				IAsymmetricBlockCipher e = new Pkcs1Encoding(new RsaEngine()).GetUnderlyingCipher();
				e.Init(false, key);

				int blockSize = e.GetInputBlockSize();

				if (data != null)
				{
					for (int chunkPosition = 0; chunkPosition < data.Length; chunkPosition += blockSize)
					{
						int chunkSize;

						if (data.Length <= blockSize)
							chunkSize = data.Length;
						else if ((chunkPosition + blockSize) > data.Length)
							chunkSize = data.Length - chunkPosition;
						else
							chunkSize = blockSize;

						if (chunkSize <= 0)
							break;

						output.AddRange(e.ProcessBlock(data, chunkPosition, chunkSize));
					}

					result = ByteArrayToString(output.ToArray());
				}
			}
			catch (Exception ex)
			{
				Debug.Write(ex.ToString());
			}

			return result;
		}
All Usage Examples Of Org.BouncyCastle.Crypto.Encodings.Pkcs1Encoding::Init