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 tripleDES { public static void main (String[] args) { try { //add a security provider java.security.Security.addProvider(new cryptix.provider.Cryptix()); // RawSecretKey implements a secret key in raw format. //RawKeyGenerator creates keys that are instances of this class. // parametros ("algoritmo", "chave em hexadecimal") RawSecretKey key2 = new RawSecretKey("DES-EDE3",Hex.fromString("3812A419C63BE771AD9F61FEFA20CE633812A419C63BE771")); // Use the following line instead for DES encryption // RawSecretKey key2 = new RawSecretKey("DES",Hex.fromString("3812A419C63BE771")); // Returns: a copy of the raw-encoded key data byte[] yval = key2.getEncoded(); System.out.println("\n********************************************************"); System.out.println("Yval = "+yval.toString()); BigInteger Bkey = new BigInteger(yval); //Dump a BigInteger as a string, in a format that is easy to read for debugging purposes. //The string m is prepended to the start of each line. String w = cryptix.util.core.BI.dumpString(Bkey); System.out.println("\n********************************************************"); System.out.println("The Encryption Key = " + w); //retorna um objeto Cipher que implementa a cifra fornecida pelo fornecido provedor Cipher des= Cipher.getInstance("DES-EDE3/ECB/NONE","Cryptix"); //inicializa a encriptação com a chave fornecida. des.initEncrypt(key2); //encripta byte[] ciphertext = des.crypt(Hex.fromString("01010101010101010102030405060708090A0B0C0D0E0F101112131415161718")); System.out.println("\n********************************************************"); System.out.println("ciphertext.length = " + ciphertext.length); BigInteger Bciph = new BigInteger(ciphertext); w = cryptix.util.core.BI.dumpString(Bciph); System.out.println("\n********************************************************"); System.out.println("Ciphertext for simple encryption = " + w); //decrypt ciphertext des.initDecrypt(key2); ciphertext = des.crypt(ciphertext); System.out.println("\n********************************************************"); System.out.println("plaintext.length = " + ciphertext.length); // print out representation of decrypted ciphertext Bciph = new BigInteger(ciphertext); w = cryptix.util.core.BI.dumpString(Bciph); System.out.println("\n********************************************************"); System.out.println("Plaintext for simple encryption = " + w); } catch (Exception e) { System.err.println("Caught exception " + e.toString()); } }}