Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Seeking DES Algorithm helpers

658018Mar 11 2008
I will explain a little bit of my my program. We have POS terminals, so what happen there the PIN block is encrypted by 16 digits symmetric key which is issued by me. After that the terminal will send the data to my program and in my program I will decrypt the PIN block using same key. Then get the PIN block at my program. The using algorithm is DES in the terminal and the PIN block length is 16.

Clear Pin Block =FC44A222BC33D555
key =0000111122223333
And after encrypting the PIN block it just same as clear PIn block (Ex c659899b02402542)
Then I expected the clear Pin block after decrypting it in my program using same key But is wrong


What is the good java API for doing that? or if you know any good way for doing that Please let me know

I just follow the this code but it will not fulfill my requirement

import java.io.*;
import java.security.*;
import java.math.*;

import xjava.security.Cipher;
import cryptix.util.core.BI;
import cryptix.util.core.ArrayUtil;
import cryptix.util.core.Hex;
import cryptix.provider.key.*;

class testDES {

public static void main (String[] args) {
java.security.Security.addProvider(new cryptix.provider.Cryptix());
try {

//FileOutputStream outFile1 = new FileOutputStream("DES.out");
// Note: PrintStream is deprecated, but still works fine in jdk1.1.7b
//PrintStream output1 = new PrintStream(outFile1);

// convert a string to a DES key and print out the result
RawSecretKey key2 = new RawSecretKey("DES",Hex.fromString("f86410fa2d6e2634"));
RawKey rkey = (RawKey) key2;
byte[] yval = rkey.getEncoded();
BigInteger Bkey = new BigInteger(yval);
String w = cryptix.util.core.BI.dumpString(Bkey);
System.out.println("The Encryption Key = " + w);
//output1.println("The Encryption Key = " + w);

// use the DES key to encrypt a string
Cipher des=Cipher.getInstance("DES/ECB/NONE","Cryptix");

//des.initEncrypt(key2);
//byte[] ciphertext = des.crypt(Hex.fromString("c659899b02402542"));
// output1.print("\n");
//System.out.println("ciphertext.length = " + ciphertext.length);
//output1.println("ciphertext.length = " + ciphertext.length);

//BigInteger Bciph = new BigInteger(ciphertext);
//w = cryptix.util.core.BI.dumpString(Bciph);
//output1.println("Ciphertext for DES encryption = " + w);

// decrypt ciphertext
byte[] ciphertext = des.crypt(Hex.fromString("c659899b02402542"));

des.initDecrypt(key2);
ciphertext = des.crypt(ciphertext);
//output1.print("\n");
System.out.println("plaintext.length = " + ciphertext.length);
//output1.println("plaintext.length = " + ciphertext.length);

// print out representation of decrypted ciphertext
BigInteger Bciph = new BigInteger(ciphertext);
w = cryptix.util.core.BI.dumpString(Bciph);
//output1.println("Plaintext for DES encryption = " + w);
System.out.println("Plaintext for DES encryption = " + w);

//output1.println(" ");
//output1.close();

} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
}

}}

soon reply
Kapila
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 8 2008
Added on Mar 11 2008
0 comments
230 views