Example #1
0
            public IRSAManager CreateManagerFromFile(string keyFile, SecureString password)
            {
                string     pemData = string.Empty;
                FileStream stream  = null;

                try
                {
                    stream = new FileStream(keyFile, FileMode.Open, FileAccess.Read);
                    StreamReader reader = new StreamReader(stream, Encoding.ASCII);
                    pemData = reader.ReadToEnd().Trim(new char[] { '\r', '\n' });
                }
                catch (Exception ex)
                {
                    throw new RSAException("Ошибка чтения файла." + Environment.NewLine + ex.Message);
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close();
                    }
                }
                RSACryptoServiceProvider provider = RSAHelper.CreateProviderFromKey(pemData, password);

                if (provider == null)
                {
                    throw new RSAException("Error create RSAManager.");
                }
                IRSAManager result = new RSAManager(provider, DefaultEncoding);

                return(result);
            }
Example #2
0
            public IRSAManager CreateManager(string pemData, SecureString password, Encoding dataEncoding)
            {
                RSACryptoServiceProvider provider = RSAHelper.CreateProviderFromKey(pemData, password);
                IRSAManager result = new RSAManager(provider, dataEncoding);

                return(result);
            }