Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3DES Key Components

I need to encrypt/decrypt data using 3DES. the Keys shared with me are in the form of;

Component 1 = 11111111111111111111111111111111

Component 2 = 22222222222222222222222222222222

KVC = ABCD1234

I need to create 3DES Key from the above components, or K1,k2,k3 sub keys,

I understand sub keys are 16 bytes long, however these are 32 bytes long.

Please share the procedure to create 3DES key.

like image 926
kasai Avatar asked Dec 01 '25 03:12

kasai


1 Answers

Transform the clear components in to byte arrays using HexStringToByte standard method. Pass the 3 byte arrays to the method below. You can verify your results at http://www.emvlab.org/keyshares/. Here are sample data:

  • cc1: 447FC2AA6EFFFEE5405A559E88DC958C
  • cc2: 1086F0493DB0EFE42EDF1BC99541E96F
  • cc3: D1C603D64D1EDC9D3CA78CD95D168E40
  • result key: 853F31351E51CD9C5222C28E408BF2A3
  • result key kvc: 1E49C1
public static byte[] buildKey(byte[] cc1, byte[] cc2, byte[] cc3) {
  byte[] result = new byte[cc1.length];
  int i = 0;
  for (byte b1: cc1) {
    byte b2 = cc2[i];
    byte b3 = cc3[i];
    result[i] = (byte)(b1 ^ b2 ^ b3);
    i++;
  }
  return result;
}
like image 54
Slav Avatar answered Dec 06 '25 04:12

Slav