• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1186
  • Last Modified:

PasswordDeriveBytes Question

Hello,

I'm experimenting with this code (trying to get an understanding of how encryption works).

I was expecting this code to output a password based upon the parameters that I've placed into it.  The actual output from this code is:

System.Security.Cryptography.PasswordDeriveBytes
Press any key to continue . . .

Is this correct?  Or is there a method of PasswordDeriveBytes that I need to call?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
 
namespace PasswordDerive
{
    class Program
    {
        static void Main(string[] args)
        {
            string passPhrase = "testphase";
            string saltValue = "salt";
            string hashAlgorithm = "SHA1";
            int passwordIterations = 2;
 
            byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
 
            PasswordDeriveBytes password = new PasswordDeriveBytes(
                                                passPhrase,
                                                saltValueBytes,
                                                hashAlgorithm,
                                                passwordIterations);
 
 
 
            Console.WriteLine(password);
 
        }
    }
}

Open in new window

0
andyw27
Asked:
andyw27
1 Solution
 
LordOfPortsCommented:
Depending on what you are trying to do you can review the available member methods of the PasswordDeriveBytes object http://msdn.microsoft.com/en-us/library/system.security.cryptography.passwordderivebytes_members.aspx

The key it generates is not really readable in the normal sense, you could for example output a base64 encoded string to see some sample output like in the code snippet below (simply replace line 28 above). Its real purpose is to generate a secure key for an ecryption algorithm, you can see good examples and references of its intended usage at:

http://msdn.microsoft.com/en-us/library/system.security.cryptography.passwordderivebytes.cryptderivekey.aspx 
http://blogs.msdn.com/shawnfa/archive/2004/04/14/113514.aspx

Console.WriteLine(Convert.ToBase64String(password.GetBytes(16)));

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now