Esempio n. 1
0
        public static CraChallenge Create(IDictionary <string, string> extra)
        {
            if (extra == null || !extra.TryGetValue("salt", out string salt))
            {
                return(null);
            }
            else
            {
                CraChallenge result = new CraChallenge();

                result.Salt = salt;


                if (extra.TryGetValue("iterations", out string strTemp))
                {
                    if (int.TryParse(strTemp, out int iterations))
                    {
                        result.Iterations = iterations;
                    }
                }


                if (extra.TryGetValue("keylen", out strTemp))
                {
                    if (int.TryParse(strTemp, out int keyLen))
                    {
                        result.KeyLength = keyLen;
                    }
                }

                return(result);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Computes a derived cryptographic key from a password according to PBKDF2
        /// http://en.wikipedia.org/wiki/PBKDF2. The function will only return a derived key
        /// if at least 'salt' is present in the 'extra' dictionary. The complete set of
        /// attributes that can be set in 'extra':
        ///    salt: The salt value to be used.
        ///    iterations: Number of iterations of derivation algorithm to run.
        ///    keylen: Key length to derive.
        /// </summary>
        /// <param name="secret">The secret key from which to derive. </param>
        /// <param name="extra"> Extra data for salting the secret. Possible key values 'salt'
        /// (required, otherwise returns @secret), 'iterations' (1000 default),
        /// and/or 'keylen' (32 default). </param>
        /// <returns>A derived key (Base64 encoded) if a salt is provided in the extra parameter, or the
        /// value of parameter 'secret' if not.</returns>
        public static string DeriveKey(string secret, IDictionary <string, string> extra)
        {
            IWampCraChallenge adapter = CraChallenge.Create(extra);

            string result = DeriveKey(secret, adapter);

            return(result);
        }
Esempio n. 3
0
 /// <summary>
 /// Compute the authentication signature from an authentication challenge and a secret.
 /// </summary>
 /// <param name="authChallenge">The authentication challenge. </param>
 /// <param name="authSecret">The authentication secret. </param>
 /// <param name="authExtra">Extra data for salting the secret. Possible key values 'salt'
 /// (required, otherwise uses @authSecret), 'iterations' (1000
 /// default), and/or 'keylen' (32 default). </param>
 /// <returns>The authentication signature.</returns>
 public static string AuthSignature(string authChallenge, string authSecret, IDictionary <string, string> authExtra)
 {
     return(AuthSignature(authChallenge, authSecret, CraChallenge.Create(authExtra)));
 }