Inheritance: IKeyDerivationParameters
Exemple #1
0
        public string SampleDeriveFromPbkdf(
            String strAlgName,
            UInt32 targetSize)
        {
            // Open the specified algorithm.
            KeyDerivationAlgorithmProvider objKdfProv = KeyDerivationAlgorithmProvider.OpenAlgorithm(strAlgName);

            // Create a buffer that contains the secret used during derivation.
            String  strSecret  = "MyPassword";
            IBuffer buffSecret = CryptographicBuffer.ConvertStringToBinary(strSecret, BinaryStringEncoding.Utf8);

            // Create a random salt value.
            IBuffer buffSalt = CryptographicBuffer.GenerateRandom(32);

            // Specify the number of iterations to be used during derivation.
            UInt32 iterationCount = 10000;

            // Create the derivation parameters.
            KeyDerivationParameters pbkdf2Params = KeyDerivationParameters.BuildForPbkdf2(buffSalt, iterationCount);

            // Create a key from the secret value.
            CryptographicKey keyOriginal = objKdfProv.CreateKey(buffSecret);

            // Derive a key based on the original key and the derivation parameters.
            IBuffer keyDerived = CryptographicEngine.DeriveKeyMaterial(
                keyOriginal,
                pbkdf2Params,
                targetSize);

            // Encode the key to a hexadecimal value (for display)
            String strKeyHex = CryptographicBuffer.EncodeToHexString(keyDerived);

            // Return the encoded string
            return(strKeyHex);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyDerivationParameters"/> class.
        /// </summary>
        /// <param name="parameters">The platform parameters.</param>
        internal KeyDerivationParameters(Platform.KeyDerivationParameters parameters)
        {
            Requires.NotNull(parameters, "parameters");

            this.Parameters = parameters;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyDerivationParameters"/> class.
        /// </summary>
        /// <param name="parameters">The platform parameters.</param>
        internal KeyDerivationParameters(Platform.KeyDerivationParameters parameters)
        {
            Requires.NotNull(parameters, "parameters");

            this.platform = parameters;
        }