Esempio n. 1
0
        private static string GetSecret(string login, string pwd, string token)
        {
            //string msg = login + "---" + pwd; --> old format

            //1-key must be a fixed 16 bytes (pad / truncate if necessary)
            byte[] KeyBytes = AESCryptohandler.makePassPhrase(token);
            //2-set the key - NOTE: iv will be the same as the key
            byte[] IV = KeyBytes;

            //3-//convert the JSON object to a string
            var msg = new
            {
                UserId   = login,
                Password = pwd
            };
            string strMsg = JsonConvert.SerializeObject(msg);

            //4-Run the encryption in CBC mode!
            byte[] encrypted = AESCryptohandler.EncryptStringToBytes(strMsg, KeyBytes, IV);

            //5- Convert byte array to base64
            string secret = Convert.ToBase64String(encrypted);

            //6-Roundtrip test
            string roundtrip = AESCryptohandler.DecryptStringFromBytes(encrypted, KeyBytes, IV);

            return(secret);
        }
Esempio n. 2
0
        private static void DecryptTest()
        {
            string Token  = "9aac2d7d-4a28-458d-955e-c962d2e6e59c";
            string Secret = "S9e80BH7LRKSGKRKydpGrX7ezgX6Lh9Hb8hWOTZ6o55ARVa3KVPBYBlDuKbVTbsl";

            byte[] KeyBytes = AESCryptohandler.makePassPhrase(Token);

            byte[] IV = KeyBytes;

            byte[] msgToDecrypt = Convert.FromBase64String(Secret);

            string origMsg = AESCryptohandler.DecryptStringFromBytes(msgToDecrypt, KeyBytes, IV);
        }