//************************************************************************* // // DeriveKeyM // Derive key material using PKCS #1 v1.5 algorithm with MD5 hash // // Copyright (C) 2005. Michel I. Gallant // //************************************************************************* // // DeriveKeyM.cs // // Derive a key from a pswd and Salt using MD5 and PKCS #5 v1.5 approach // see also: http://www.openssl.org/docs/crypto/EVP_BytesToKey.html // see also: http://java.sun.com/j2se/1.5.0/docs/guide/security/jce/JCERefGuide.html#PBE // //************************************************************************** using System; using System.IO; using System.Text; using System.Security.Cryptography; public class DeriveKeyM{ public static void Main(String[] args) { if(args.Length < 4) { Console.WriteLine("Usage: DeriveKey ") ; return; } int HASHLENGTH = 16; //MD5 bytes String chars = args[0]; String hexstr = args[1] ; int count = Int32.Parse(args[2]); int miter = Int32.Parse(args[3]) ; byte[] keymaterial = new byte[HASHLENGTH*miter] ; //to store contatenated Mi hashed results // --- get secret password bytes ---- byte[] psbytes; UTF8Encoding utf8 = new UTF8Encoding(); psbytes = utf8.GetBytes(chars); // --- decode hex-encoded salt string into bytes --- byte[] salt = new byte[hexstr.Length/2]; for (int i=0; i