예제 #1
0
            /// <summary>
            /// RSA encryption
            /// SHA256 hash algorithm to use the key length of at least 2048
            /// </summary>
            /// <param name="encoding">Data coding</param>
            /// <param name="keySize">Key length in bits:</param>
            /// <param name="privateKey">private Key</param>
            /// <param name="publicKey">public Key</param>
            public RsaXmlUtil(Encoding encoding, string publicKey, string privateKey = null, int keySize = 2048)
            {
                if (string.IsNullOrEmpty(privateKey) && string.IsNullOrEmpty(publicKey))
                {
                    throw new ArgumentException("Public and private keys must not be empty at the same time");
                }

                if (!string.IsNullOrEmpty(privateKey))
                {
#if NET451 || NET452
                    PrivateRsa = new MsRSA {
                        KeySize = keySize
                    };
#else
                    PrivateRsa         = MsRSA.Create();
                    PrivateRsa.KeySize = keySize;
#endif
                    PrivateRsa.ImportKeyInLvccXml(privateKey);
                }

                if (!string.IsNullOrEmpty(publicKey))
                {
#if NET451 || NET452
                    PublicRsa = new MsRSA {
                        KeySize = keySize
                    };
#else
                    PublicRsa         = MsRSA.Create();
                    PublicRsa.KeySize = keySize;
#endif
                    PublicRsa.ImportKeyInLvccXml(publicKey);
                }

                DataEncoding = encoding.SafeEncodingValue();
            }