static byte[] MakeAuthentication(JToken token)
            {
                var cipher = token.ToObject <byte[]> ();

                using (var aes = new System.Security.Cryptography.AesManaged()) {
                    using (var key = Sas.SecureHelper.APP_KEY)
                        aes.Key = key.GetByte(Convert.FromBase64String);
                    using (var iv = Sas.SecureHelper.APP_IV)
                        aes.IV = iv.GetByte(Convert.FromBase64String);

                    using (var question = aes.Decrypt(cipher.ToArray())) {
                        var val = SasUtil.Evaluate(question.GetByte(b => b));
                        question.AppendChar('=');
                        foreach (var ch in val.ToString())
                        {
                            question.AppendChar(ch);
                        }

                        return(question.GetByte(aes.Encrypt));
                    }
                }
            }
Esempio n. 2
0
File: Cipher.cs Progetto: avs009/gsf
        /// <summary>
        /// Returns a binary array of decrypted data for the given parameters.
        /// </summary>
        /// <param name="source">Binary array of data to decrypt.</param>
        /// <param name="startIndex">Offset into <paramref name="source"/> buffer.</param>
        /// <param name="length">Number of bytes in <paramref name="source"/> buffer to decrypt starting from <paramref name="startIndex"/> offset.</param>
        /// <param name="key">Encryption key to use to decrypt data.</param>
        /// <param name="iv">Initialization vector to use to decrypt data.</param>
        /// <param name="strength">Cryptographic strength to use when decrypting data.</param>
        /// <returns>A decrypted version of the source data.</returns>
        public static byte[] Decrypt(this byte[] source, int startIndex, int length, byte[] key, byte[] iv, CipherStrength strength)
        {
            if (strength == CipherStrength.None)
                return source;

            AesManaged symmetricAlgorithm = new AesManaged();

            symmetricAlgorithm.KeySize = (int)strength;

            return symmetricAlgorithm.Decrypt(source, startIndex, length, key, iv);
        }