Ejemplo n.º 1
0
        //返回商店物品列表
        private byte[] ShopListResponseEncodeParser(object message)
        {
            string jsonStr = JsonConvert.SerializeObject(message, Formatting.None);

            byte[] messageBytes = Encoding.UTF8.GetBytes(jsonStr);

            messageBytes = AESCrypto.Encrypt(messageBytes, SecretKey, SecretVector);

            messageBytes = SnappySharp.Compress(messageBytes);

            return(messageBytes);
        }
Ejemplo n.º 2
0
 private Token getToken()
 {
     try
     {
         var now         = Helper.GetSecondTimeStamp();
         var timestamp   = AESCrypto.ToBytes(string.Format("{0}", now));
         var encryptTime = m_crypto.Encrypt(timestamp);
         var param       = new Dictionary <string, object>()
         {
             { "buin", m_buin },
             { "appId", m_appId },
             { "encrypt", encryptTime }
         };
         var client = new HttpClient();
         var rsp    = client.Post(this.apiGetToken(), param, HttpContentTypes.ApplicationJson);
         Helper.CheckHttpStatus(rsp);
         var body = rsp.StaticBody <Dictionary <string, object> >(overrideContentType: HttpContentTypes.ApplicationJson);
         Helper.CheckApiStatus(body);
         var    encrypt   = Helper.GetEncryptJsonValue(body);
         var    buffer    = m_crypto.Decrypt(encrypt);
         var    tokenInfo = new JsonReader().Read <Dictionary <string, object> >(AESCrypto.ToString(buffer));
         object accessToken;
         object expireIn;
         if (!tokenInfo.TryGetValue("accessToken", out accessToken) ||
             accessToken is string == false ||
             ((string)accessToken).Length == 0 ||
             !tokenInfo.TryGetValue("expireIn", out expireIn) ||
             expireIn is int == false ||
             (int)expireIn <= 0)
         {
             throw new ParamParserException("invalid token or expireIn", null);
         }
         return(new Token((string)accessToken, now, (int)expireIn));
     }
     catch (WebException e)
     {
         throw new HttpRequestException(0, e.Message, e);
     }
     catch (Exception e)
     {
         if (e is GeneralEntAppException)
         {
             throw e;
         }
         else
         {
             throw new UnexpectedException(e.Message, e);
         }
     }
 }
Ejemplo n.º 3
0
        public void Test()
        {
            using (var aesCrypto = new AESCrypto())
            {
                aesCrypto.Initialize(new Dictionary <string, object>
                {
                    { "Key", "awVFRYPeTTrA9T7OOzaAFUvu8I/ZyYjAtIzEjCmzzYw=" },
                    { "IV", "7cFxoI3/k1wxN9P6rEyR/Q==" }
                });
                var plainText = "SmartSql";

                var cipherText  = aesCrypto.Encrypt(plainText);
                var decryptText = aesCrypto.Decrypt(cipherText);
                Assert.Equal(plainText, decryptText);
                cipherText  = aesCrypto.Encrypt(plainText);
                decryptText = aesCrypto.Decrypt(cipherText);
                Assert.Equal(plainText, decryptText);
                cipherText  = aesCrypto.Encrypt(plainText);
                decryptText = aesCrypto.Decrypt(cipherText);
                Assert.Equal(plainText, decryptText);
            }
        }
Ejemplo n.º 4
0
        public static void Main()
        {
            //pruebasMetodo1();
            string textoPlano = "Texto para encriptar";
            string textoClave = "Esto es una clave";


            string encriptado = AESCrypto.Encrypt(textoPlano, textoClave);

            Console.WriteLine("Texto plano: {0}", textoPlano);
            Console.WriteLine("Encrypted: {0}", encriptado);
            string desencriptado = AESCrypto.Decrypt(encriptado, textoClave);

            Console.WriteLine("Desencriptado: {0}", desencriptado);
            Console.ReadKey();
        }
Ejemplo n.º 5
0
 public String EncryptToo(String plainText)
 {
     AESCrypto aes = new AESCrypto();
     var cipherText = aes.Encrypt(plainText);
     return cipherText + " | " + aes.Decrypt(cipherText);
 }
Ejemplo n.º 6
0
        public void Encrypt_Test()
        {
            var encryptedStr = AESCrypto.Encrypt("gang.yang", scrambledKey);

            Assert.IsTrue(encryptedStr == "WDDJcMk/+qc0CJ2QYjqXlg==", encryptedStr);
        }