コード例 #1
0
 protected virtual byte[] Encryptor(byte[] bytes)
 {
     /**
      * 对数据加密
      * 用密码加密数据
      * 对数据签名
      * */
     bytes = Cryptor.Encryptor(bytes);
     bytes = AesCryptoHelper.Encrypt(bytes, GetKeyBytesByPasword(), null);
     bytes = Sign.Sign(bytes, GetSignBytes());
     return(bytes);
 }
コード例 #2
0
        public void TestEncryptorDecryptor()
        {
            //FileReadWriteHelper fileReadWriteHelper = new FileReadWriteHelper(privateKeyDirectoryPath, fileName);
            //AESCryptor aESCryptor = new AESCryptor(new JsonSerializationHelper<KeyValuePair<String, String>>(),fileReadWriteHelper);

            ICryptor aESCryptor = Factory.CreateCryptor();

            String encrypted = Convert.ToBase64String(aESCryptor.Encryptor(Encoding.UTF8.GetBytes(input)));

            Assert.IsNotNull(encrypted);
            Console.WriteLine(encrypted);

            String outPut = Encoding.UTF8.GetString(aESCryptor.Decryptor(Convert.FromBase64String(encrypted)));

            Assert.IsNotNull(outPut);
            Console.WriteLine(outPut);
            Console.WriteLine(outPut.Length - input.Length);
            Assert.IsTrue(outPut.Length > 0);
            Assert.IsTrue(outPut.Length == input.Length);
        }