/// <summary> /// Initializes the RSA Provider with either only a public key or a public/private key pair. /// </summary> /// <param name="rsaKeyInfo">The XML string to initialize the RSA Provider with.</param> /// <param name="keySize">The length of the key.</param> /// <returns>PowerRSA object initialized with XML string.</returns> public PowerRSA(string rsaKeyInfo, int keySize) { KeySize = keySize; var keyLength = keySize; CryptoServiceProvider = new RSACryptoServiceProvider(keyLength); CryptoServiceProvider.FromXmlString(rsaKeyInfo); rsaProvider = new RSAProvider(rsaKeyInfo, keyLength); rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA256; }
/// <summary> /// Initializes the RSA Provider with either only a public key or a public/private key pair. /// </summary> /// <param name="rsaKeyInfo">The XML string to initialize the RSA Provider with.</param> /// <param name="keySize">The length of the key.</param> /// <param name="hashAlgorithm">The hash algorithm to use.</param> /// <returns>PowerRSA object initialized with XML string.</returns> public PowerRSA(string rsaKeyInfo, int keySize, PHashAlgorithm hashAlgorithm) { KeySize = keySize; var keyLength = keySize; CryptoServiceProvider = new RSACryptoServiceProvider(keyLength); CryptoServiceProvider.FromXmlString(rsaKeyInfo); rsaProvider = new RSAProvider(rsaKeyInfo, keyLength); switch ((int) hashAlgorithm) { case 0: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA1; break; case 1: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA256; break; case 2: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA512; break; } }
/// <summary> /// Initializes the RSA Provider with either only a public key or a public/private key pair. /// </summary> /// <param name="rsaKeyInfo">The XML string to initialize the RSA Provider with.</param> /// <param name="keySize">The length of the key.</param> /// <param name="hashAlgorithm">The hash algorithm to use.</param> /// <returns>PowerRSA object initialized with XML string.</returns> public PowerRSA(string rsaKeyInfo, int keySize, PHashAlgorithm hashAlgorithm) { KeySize = keySize; var keyLength = keySize; CryptoServiceProvider = new RSACryptoServiceProvider(keyLength); CryptoServiceProvider.FromXmlString(rsaKeyInfo); rsaProvider = new RSAProvider(rsaKeyInfo, keyLength); switch ((int)hashAlgorithm) { case 0: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA1; break; case 1: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA256; break; case 2: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA512; break; } }
private void InitRSA(int keySize, PHashAlgorithm hashAlgorithm) { KeySize = keySize; var keyLength = keySize; CryptoServiceProvider = new RSACryptoServiceProvider(keyLength); var rsaKeyInfo = CryptoServiceProvider.ToXmlString(true); //.Replace("><", ">\r\n<"); rsaProvider = new RSAProvider(rsaKeyInfo, keyLength); switch ((int)hashAlgorithm) { case 0: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA1; break; case 1: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA256; break; case 2: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA512; break; } }
private void InitRSA(int keySize, PHashAlgorithm hashAlgorithm) { KeySize = keySize; var keyLength = keySize; CryptoServiceProvider = new RSACryptoServiceProvider(keyLength); var rsaKeyInfo = CryptoServiceProvider.ToXmlString(true); //.Replace("><", ">\r\n<"); rsaProvider = new RSAProvider(rsaKeyInfo, keyLength); switch ((int) hashAlgorithm) { case 0: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA1; break; case 1: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA256; break; case 2: rsaProvider.RSAProviderHashAlgorithm = RSAProviderParameters.RSAProviderHashAlgorithm.SHA512; break; } }