ToXmlString() public abstract method

public abstract ToXmlString ( bool includePrivateParameters ) : string
includePrivateParameters bool
return string
        public static byte[] GetSecretKey(EncryptedKey encryptedKey, AsymmetricAlgorithm privateKey)
        {
            var keyAlgorithm = encryptedKey.EncryptionMethod.KeyAlgorithm;
            var asymmetricAlgorithm = GetAsymmetricKeyTransportAlgorithm(keyAlgorithm);
            asymmetricAlgorithm.FromXmlString(privateKey.ToXmlString(true));

            var useOaep = keyAlgorithm == EncryptedXml.XmlEncRSAOAEPUrl;
            return asymmetricAlgorithm.Decrypt(encryptedKey.CipherData.CipherValue, useOaep);
        }
Example #2
0
        /// <summary>
        /// 为非对称加密生成密钥对,并存储到文件
        /// </summary>
        /// <param name="asymmetricAlgorithm"></param>
        /// <param name="fileName"></param>
        /// <param name="isPrivate"></param>
        public static void CreateKeyFileForAsymmetricAlgorithm(AsymmetricAlgorithm asymmetricAlgorithm, string fileName, bool isPrivate)
        {
            if (string.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName");

            string content = asymmetricAlgorithm.ToXmlString(isPrivate);

            File.WriteAllText(fileName, Convert.ToBase64String(Encoding.UTF8.GetBytes(content)));
        }
Example #3
0
		private bool CompareAsymmetricAlgorithm (AsymmetricAlgorithm a1, AsymmetricAlgorithm a2)
		{
			// fast path
			if (a1.KeySize != a2.KeySize)
				return false;
			// compare public keys - if they match we can assume the private match too
			return (a1.ToXmlString (false) == a2.ToXmlString (false));
		}