In this example, we see see the following three numbers:
import java.io.*;
import java.security.*;
import java.math.*;
import cryptix.util.core.BI;
import cryptix.util.core.ArrayUtil;
import cryptix.util.core.Hex;
import cryptix.provider.key.*;
class test3des1 {
public static void main (String[] args) {
try {
FileOutputStream outFile1 = new FileOutputStream("DES-EDE3.out");
// Note: PrintStream is deprecated, but still works fine in jdk1.1.7b
PrintStream output1 = new PrintStream(outFile1);
// convert a string to a 3DES key and print out the result
RawSecretKey key2 = new RawSecretKey("DES-EDE3",Hex.fromString("3812A419C63BE771AD9F61FEFA20CE633812A419C63BE771"));
RawKey rkey = (RawKey) key2;
byte[] yval = rkey.getEncoded();
BigInteger Bkey = new BigInteger(yval);
String w = cryptix.util.core.BI.dumpString(Bkey);
output1.println("The Encryption Key = " + w);
// use the 3DES key to encrypt a string in electronic code book (ECB) mode
Cipher des=Cipher.getInstance("DES-EDE3/ECB/NONE","Cryptix");
des.initEncrypt(key2);
byte[] ciphertext = des.crypt(Hex.fromString("01010101010101010102030405060708090A0B0C0D0E0F101112131415161718"));
// print out length and representation of ciphertext
output1.print("\n");
output1.println("ciphertext.length = " + ciphertext.length);
BigInteger Bciph = new BigInteger(ciphertext);
w = cryptix.util.core.BI.dumpString(Bciph);
output1.println("Ciphertext for 3DES encryption = " + w);
// decrypt ciphertext
des.initDecrypt(key2);
ciphertext = des.crypt(ciphertext);
output1.print("\n");
output1.println("plaintext.length = " + ciphertext.length);
// print out representation of decrypted ciphertext
Bciph = new BigInteger(ciphertext);
w = cryptix.util.core.BI.dumpString(Bciph);
output1.println("Plaintext for 3DES encryption = " + w);
output1.println(" ");
output1.close();
} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
}
}}
The Encryption Key = Multi-Precision Integer 190 bits long...
sign: Positive
magnitude: 3812A419C63BE771 AD9F61FEFA20CE63 3812A419C63BE771
ciphertext.length = 32
Ciphertext for 3DES encryption = Multi-Precision Integer 255 bits long...
sign: Positive
magnitude: 741038365B8C4BC2 01B45F3A1C9C703E 5DE9007B2288BDBD 5203FEB4F80C5BD0
plaintext.length = 32
Plaintext for 3DES encryption = Multi-Precision Integer 249 bits long...
sign: Positive
magnitude: 0101010101010101 0102030405060708 090A0B0C0D0E0F10 1112131415161718
The Digital Monetary Trust, Part 1.
The Digital Monetary Trust, Part 2.