|
From: jit <ji...@tm...> - 2005-01-26 10:24:53
|
hello,I need the command to execute my cryptix32.jar file.I'm doin a security application. This file is used to encrypt and decrypt. The command i'm using is javac -classpath "C:\j2sdk1.4.2_02\lib\cryptix32.jar" *.java java MainApp Is it correct? the Crypt file source code is as follow:- import xjava.security.Cipher; import cryptix.provider.key.RawKeyGenerator; import java.math.BigInteger; import java.security.Key; import java.security.MessageDigest; import java.security.Security; import java.math.BigDecimal; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.InvalidKeyException; import java.security.KeyException; import xjava.security.WeakKeyException; /** *Implementation of the AES (Rijndael) encryption standard as been implemented in *<a href="http://www.cryptix.org/">Cryptix</a> java jce library */ public class Crypt { /** *Digest algorithm used to has the user supplied password to produce */ public static final String DIGEST_ALGO = "SHA"; public static final String CIPHER_ALGO = "Rijndael/CBC/PKCS#7"; public static final String CIPHER = "Rijndael"; public static final String PROVIDER = "Cryptix"; public static int iteration = 1000; public static byte[] digest(byte[] passBytes) throws NoSuchAlgorithmException, NoSuchProviderException { MessageDigest digest = MessageDigest.getInstance(DIGEST_ALGO,PROVIDER); return digest.digest(passBytes); file://MessageDigest digestAlgo = MessageDigest.getInstance(DIGEST_ALGO); file://digestAlgo.update(passBytes); file://return digestAlgo.digest(); } public static byte[] makeKey(String password, int size) throws NoSuchAlgorithmException, NoSuchProviderException file://password = user supplied password file://size = size of key (128, 192,256) { byte[] passBytes = digest(password.getBytes()); for (int i=0; i < iteration-1; i++) { passBytes = digest(passBytes); } System.out.println(passBytes.length); file://20 byte[] keyBytes = new byte[size/8]; System.out.println(keyBytes.length); file://16 for (int i=0; i < keyBytes.length; i++) { if (i < passBytes.length) keyBytes[i] = passBytes[i]; else keyBytes[i] = passBytes[i-passBytes.length]; } return keyBytes; } public static byte[] encrypt(String password, int keySize, byte[] data) throws Exception /*the real Exception *throws KeyException, NoSuchProviderException, NoSuchAlgorithmException, SecurityException*/ { try { file://byte[] digestedPassword = makeKey(password,keySize); Security.addProvider(new cryptix.provider.Cryptix()); RawKeyGenerator keyGenerator = (RawKeyGenerator) RawKeyGenerator.getInstance(CIPHER,PROVIDER); byte[] digestedPassword = makeKey(password,keySize); Key key = keyGenerator.generateKey(digestedPassword); Cipher cipher = Cipher.getInstance(CIPHER_ALGO,PROVIDER); cipher.initEncrypt(key); byte[] output= cipher.crypt(data); return output; } catch(KeyException e) file://at initencrypt covers both the down one { System.out.println(e); byte[] dummy = new byte[1]; return dummy; } catch(NoSuchProviderException e) file://RawKeyGenerator { System.out.println(e); byte[] dummy = new byte[1]; return dummy; } catch(NoSuchAlgorithmException e) file://RawKeyGenerator file://makekey for SHA-1 { System.out.println(e); byte[] dummy = new byte[1]; return dummy; } catch(SecurityException e) file://addProvider { System.out.println(e); byte[] dummy = new byte[1]; return dummy; } } public static byte[] decrypt(String password, int keySize, byte[] data) throws Exception /* the real exceptions throws KeyException, NoSuchProviderException, NoSuchAlgorithmException, SecurityException*/ { try { file://byte[] digestedPassword = makeKey(password,keySize); Security.addProvider(new cryptix.provider.Cryptix()); RawKeyGenerator keyGenerator = (RawKeyGenerator) RawKeyGenerator.getInstance(CIPHER,PROVIDER); byte[] digestedPassword = makeKey(password,keySize); Key key = keyGenerator.generateKey(digestedPassword); Cipher cipher = Cipher.getInstance(CIPHER_ALGO,PROVIDER); cipher.initDecrypt(key); byte[] output = cipher.crypt(data); return output; } catch(KeyException e) file://at initencrypt covers both the down one { System.out.println(e); byte[] dummy = new byte[1]; return dummy; } catch(NoSuchProviderException e) file://RawKeyGenerator { System.out.println(e); byte[] dummy = new byte[1]; return dummy; } catch(NoSuchAlgorithmException e) file://RawKeyGenerator file://makekey for SHA-1 { System.out.println(e); byte[] dummy = new byte[1]; return dummy; } catch(SecurityException e) file://addProvider { System.out.println(e); byte[] dummy = new byte[1]; return dummy; } } } |