Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Decrypt DES by password

Reply
Thread Tools

Decrypt DES by password

 
 
Thomas Dybdahl Ahle
Guest
Posts: n/a
 
      05-15-2006
Hi, I've got some DES encrypted data, for which I know the password.
The problem is that I have to generate an 8byte key from the password.
I use python-crypto-2.0.1.

I also know, that the C# way to do the decryption is:
PasswordDeriveBytes bytes1 = new
PasswordDeriveBytes("passwordString", null);
byte[] array1 = new byte[8];
byte[] array2 = bytes1.CryptDeriveKey("DES", "MD5", 0, array1);

DESCryptoServiceProvider provider1 = new DESCryptoServiceProvider();
FileStream fs = new FileStream("fileNameString", FileMode.Open,
FileAccess.Read); CryptoStream cs = new CryptoStream(fs,
provider1.CreateEncryptor(array2, array1), CryptoStreamMode.Read);

Anybody know how to do this in python?

--
Programmers should realize their critical importance and responsibility in a
world gone digital. They are in many ways similar to the priests and monks of
Europe's Dark Ages; they are the only ones with the training and insight
to read and interpret the "scripture" of this age.

 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      05-15-2006
Thomas Dybdahl Ahle <(E-Mail Removed)> writes:
> byte[] array2 = bytes1.CryptDeriveKey("DES", "MD5", 0, array1);
> > Anybody know how to do this in python?


I'm not aware of a standard that says how CryptDeriveKey is supposed
to work. Or rather, there are multiple possible standard ways to do
it. If you can find an exact specification, or C# source code that
does it, it will probably be straightforward to reimplement in Python.

If you want to just do something generic and don't need to
interoperate with a C# application that uses CryptDeriveKey, the
following should be ok:

import hmac
password = 'the big sekrit password goes here'

key1 = hmac.HMAC(password, '1').digest()[:8] # get 8 bytes

And if you need additional keys, such as for triple DES:

key2 = hmac.HMAC(password, '2').digest()[:8] # get 8 bytes
key3 = hmac.HMAC(password, '3').digest()[:8] # get 8 bytes

If you want to be fancier you could try PKCS5 KDF2:

http://www.rsasecurity.com/rsalabs/node.asp?id=2127

CryptDeriveKey may in fact be doing something like this.
 
Reply With Quote
 
 
 
 
Thomas Dybdahl Ahle
Guest
Posts: n/a
 
      05-16-2006
Den Mon, 15 May 2006 11:32:47 -0700. skrev Paul Rubin:
> Thomas Dybdahl Ahle <(E-Mail Removed)> writes:
>> byte[] array2 = bytes1.CryptDeriveKey("DES", "MD5", 0, array1);
>> > Anybody know how to do this in python?

>
> I'm not aware of a standard that says how CryptDeriveKey is supposed
> to work. Or rather, there are multiple possible standard ways to do
> it. If you can find an exact specification, or C# source code that
> does it, it will probably be straightforward to reimplement in Python.


I tried to find out how the monofolks did it, but also they didn't know
the algorithms. Maybe I should find a windows computer with .net, create
the key and base64 encode it, so that I could take it to the python
program...

But thanks for the excample anyways. Maybe I can use it, if I need to
encrypt something myself, another time.

--
Programmers should realize their critical importance and responsibility in a
world gone digital. They are in many ways similar to the priests and monks of
Europe's Dark Ages; they are the only ones with the training and insight
to read and interpret the "scripture" of this age.

 
Reply With Quote
 
Paul Rubin
Guest
Posts: n/a
 
      05-16-2006
Thomas Dybdahl Ahle <(E-Mail Removed)> writes:
> > I'm not aware of a standard that says how CryptDeriveKey is supposed
> > to work....

> I tried to find out how the monofolks did it, but also they didn't know
> the algorithms.


Actually this is almost certainly an entry into the Windows Crypto API.
If you're persistent you might be able to figure it out from the CAPI
does at http://msdn.microsoft.com. Start by typing CryptDeriveKey
into the search box and follow links and do more searches from there.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FREE SERVICE NTLM HASH DECRYPT PASSWORD Libre Computer Security 1 03-25-2009 03:54 PM
decrypt challenge - perl encrypt with ruby decrypt aktxyz@gmail.com Ruby 1 06-16-2007 01:30 PM
Password encrypt/decrypt Microsoft ASP .Net 1 10-05-2005 10:58 AM
encrypt with TripleDES, decrypt with DES, doesnt work ? Lech Migdal ASP .Net Security 1 04-07-2004 05:48 PM
How do I decrypt a SHA stored password? Augusto Rocha ASP .Net 2 02-19-2004 10:55 PM



Advertisments