コード例 #1
0
        public void GeneratePrivateKetTest()
        {
            RsaCryptoService.GeneratePrivateKey(FullPath);

            Assert.That(File.Exists(FullPath), Is.True);
            Console.Out.WriteLine(File.ReadAllText(FullPath));
        }
コード例 #2
0
        /// <summary>
        /// 对密文进行解密
        /// </summary>
        /// <param name="encryptedStr"></param>
        /// <returns></returns>
        private string DecryptStr(string encryptedStr)
        {
            var path       = Server.MapPath("~/config/keys.config");
            var privateKey = new XmlHelper(path).GetValue("privateKey").Trim();

            var rsa        = new RsaCryptoService(privateKey);
            var decryptStr = rsa.Decrypt(encryptedStr);

            return(decryptStr);
        }
コード例 #3
0
        public void EncryptDecryptDataTest()
        {
            RsaCryptoService.GeneratePrivateKey(FullPath);

            string data        = "123456789";
            string encryptData = _rsaCryptoService.EncryptData(FullPath, data);

            Console.Out.WriteLine("Password: " + encryptData);

            string decryptData = _rsaCryptoService.DecryptData(FullPath, encryptData);

            Assert.That(data, Is.EqualTo(decryptData));
        }
コード例 #4
0
        public void SetUp()
        {
            _rsaCryptoService = new RsaCryptoService();

            string path = Path.Combine(RootPath, TestDirectory);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (File.Exists(FullPath))
            {
                File.Delete(FullPath);
            }
        }