Mono.Security.Cryptography.RSAManaged.ExportParameters C# (CSharp) Method

ExportParameters() public method

public ExportParameters ( bool includePrivateParameters ) : RSAParameters
includePrivateParameters bool
return System.Security.Cryptography.RSAParameters
		public override RSAParameters ExportParameters (bool includePrivateParameters) 
		{
			if (m_disposed)
				throw new ObjectDisposedException (Locale.GetText ("Keypair was disposed"));

			if (!keypairGenerated)
				GenerateKeyPair ();
	
			RSAParameters param = new RSAParameters ();
			param.Exponent = e.GetBytes ();
			param.Modulus = n.GetBytes ();
			if (includePrivateParameters) {
				// some parameters are required for exporting the private key
				if (d == null)
					throw new CryptographicException ("Missing private key");
				param.D = d.GetBytes ();
				// hack for bugzilla #57941 where D wasn't provided
				if (param.D.Length != param.Modulus.Length) {
					byte[] normalizedD = new byte [param.Modulus.Length];
					Buffer.BlockCopy (param.D, 0, normalizedD, (normalizedD.Length - param.D.Length), param.D.Length);
					param.D = normalizedD;
				}
				// but CRT parameters are optionals
				if ((p != null) && (q != null) && (dp != null) && (dq != null) && (qInv != null)) {
					// and we include them only if we have them all
					int length = (KeySize >> 4);
					param.P = GetPaddedValue (p, length);
					param.Q = GetPaddedValue (q, length);
					param.DP = GetPaddedValue (dp, length);
					param.DQ = GetPaddedValue (dq, length);
					param.InverseQ = GetPaddedValue (qInv, length);
				}
			}
			return param;
		}

Usage Example

コード例 #1
0
ファイル: RSAManagedTest.cs プロジェクト: REALTOBIZ/mono
		private void EncryptDecrypt (string msg, RSAManaged rsa) 
		{
			RSAParameters param = rsa.ExportParameters (false);

			byte[] data = { 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 };
			// we don't need the private key to encrypt
			RSAManaged pubkey = new RSAManaged ();
			pubkey.ImportParameters (param);
			byte[] enc = pubkey.EncryptValue (data);

			byte[] dec = rsa.DecryptValue (enc);
			// note: the decrypted value is now right padded with zeros
			Assert.IsTrue (BitConverter.ToString (dec).EndsWith (BitConverter.ToString (data)), msg);
		}
All Usage Examples Of Mono.Security.Cryptography.RSAManaged::ExportParameters