Cookbook:Computing CD Key Hashes

From BF2 Technical Information Wiki
Revision as of 19:27, 21 June 2018 by Pireax (talk | contribs) (Created page with "== Problem == You have one or more BF2 CD keys that you want to convert into key hashes. BF2 uses [http://en.wikipedia.org/wiki/MD5 MD5] [ht...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Problem

You have one or more BF2 CD keys that you want to convert into key hashes. BF2 uses MD5 hashes of players' CD keys to uniquely identify their copy of BF2. This is usually used in connection with some of the player banning functions, but has other uses as well. Sometimes it's useful to have a way to convert CD keys into hashes yourself.

Solution

Here are two solutions, depending on what it is you would like to accomplish:

If you just want to find your own CD key hash, the easiest way to do it is to use the BF2_Key_Hasher program; it reads the CD key from your game and pops up an easy-to-read dialog box that gives you your hash.

On the other hand, if you have a list of CD keys that you want to convert to hashes (something cybercafes, for example, commonly need to do), or if you want to incorporate the process into your own software for some reason, or if you just want to understand the algorithm that's used, here's a short Python function that does the job:

import md5
 
  def keyHash(cdKey):
      '''Returns the MD5 hash of a BF2 CD key, after removing any
         dashes and uppercasing.'''
      cleanCdKey = cdKey.replace('-','').upper()
      return md5.new(cleanCdKey).hexdigest()

Discussion

The algorithm is very simple: just remove any dashes ("-") from the CD key, convert everything to upper-case, then run it through the standard MD5 algorithm.

Here's an example of how to use this function:

print keyHash("J6EK-Y8JM-HT2P-QQRF-Y21E") # No, it's not a real key!
# prints the CD key hash: 5745588be00e1a65a334f4a71d738106

Submitted By

--Woody