Esempio n. 1
0
        public static string Decrypt(string encryptedData)
        {
            try
            {
                byte[] inputArray = Convert.FromBase64String(encryptedData);

                SecurityCodecs codec = new SecurityCodecs();
                TripleDESCryptoServiceProvider provider = codec.DES3Provider();

                ICryptoTransform cTransform  = provider.CreateDecryptor();
                byte[]           resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);

                provider.Clear();
                provider.Dispose();
                codec.Dispose();

                return(UTF32Encoding.UTF32.GetString(resultArray));
            }
            catch { return(encryptedData); }
        }
Esempio n. 2
0
        private void VerifySignatureInfo()
        {
            int ikid = 0;

            if (!int.TryParse(_Envelope.kid, out ikid))
            {
                throw new ArgumentOutOfRangeException("Key ID should be a number more than 0, PassedVal:" + _Envelope.kid);
            }

            if (ikid > ConfigProvider.ConfigurationStore.LiveAuthKeyCount)
            {
                throw new ArgumentOutOfRangeException(string.Format("Key ID: {0}, is not configured properly or not loaded.", ikid));
            }

            _CurrentSecretKey = ConfigProvider.ConfigurationStore.LiveAuthKeys[ikid];

            byte[] bKey = SOSCodecs.UTF8Encoder.GetBytes(_CurrentSecretKey + "JWTSig");

            SHA256Managed SHAprovider = SecurityCodecs.SHA256CryptoProvider;

            byte[] bCryptKey = SHAprovider.ComputeHash(bKey);

            byte[] bCombined = SOSCodecs.UTF8Encoder.GetBytes(_RawToken.Envelope + "." + _RawToken.Claims);

            SecurityCodecs codec = new SecurityCodecs();

            HMACSHA256 HMACHACryptoProvider = codec.HMACSHA256Provider(bCryptKey);

            _IsTokenValid = SOSCodecs.UrlEncode(HMACHACryptoProvider.ComputeHash(bCombined)) == _RawToken.Signature;

            codec.Dispose();

            SHAprovider.Clear();
            SHAprovider.Dispose();

            HMACHACryptoProvider.Clear();
            HMACHACryptoProvider.Dispose();
        }