static PbeParametersGenerator MakePbeGenerator(
            string	type,
            IDigest	digest,
            byte[]	key,
            byte[]	salt,
            int		iterationCount)
        {
            PbeParametersGenerator generator;

            if (type.Equals(Pkcs5S1))
            {
                generator = new Pkcs5S1ParametersGenerator(digest);
            }
            else if (type.Equals(Pkcs5S2))
            {
                generator = new Pkcs5S2ParametersGenerator();
            }
            else if (type.Equals(Pkcs12))
            {
                generator = new Pkcs12ParametersGenerator(digest);
            }
            else if (type.Equals(OpenSsl))
            {
                generator = new OpenSslPbeParametersGenerator();
            }
            else
            {
                throw new ArgumentException("Unknown PBE type: " + type, "type");
            }

            generator.Init(key, salt, iterationCount);
            return generator;
        }
Esempio n. 2
0
 private static byte[] SingleIterationPBKDF2(byte[] P, byte[] S, int dkLen)
 {
     PbeParametersGenerator pGen = new Pkcs5S2ParametersGenerator(new Sha256Digest());
     pGen.Init(P, S, 1);
     KeyParameter key = (KeyParameter)pGen.GenerateDerivedMacParameters(dkLen * 8);
     return key.GetKey();
 }