|
From: <pe...@us...> - 2003-11-18 23:34:58
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto
In directory sc8-pr-cvs1:/tmp/cvs-serv4173/src/java/org/neuclear/commons/crypto
Modified Files:
CryptoTools.java
Log Message:
Payment Web Application is getting there.
Index: CryptoTools.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/CryptoTools.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CryptoTools.java 11 Nov 2003 21:17:48 -0000 1.1
--- CryptoTools.java 18 Nov 2003 23:34:55 -0000 1.2
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/11/18 23:34:55 pelle
+ * Payment Web Application is getting there.
+ *
* Revision 1.1 2003/11/11 21:17:48 pelle
* Further vital reshuffling.
***************
*** 179,185 ****
--- 182,190 ----
import javax.crypto.Cipher;
+ import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
+ import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.math.BigInteger;
***************
*** 191,194 ****
--- 196,200 ----
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
+ import java.security.spec.KeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.security.spec.X509EncodedKeySpec;
***************
*** 344,347 ****
--- 350,375 ----
}
+ public static Cipher getCipher(byte key[], boolean doencrypt) throws CryptoException {
+ try {
+ Cipher cipher = Cipher.getInstance("AES", "BC");
+ KeySpec keyspec = new SecretKeySpec(key, "AES");
+ SecretKeyFactory kf = SecretKeyFactory.getInstance("AES", "BC");
+ Key skey = kf.generateSecret(keyspec);
+ cipher.init(doencrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, skey);
+ return cipher;
+ } catch (NoSuchAlgorithmException e) {
+ rethrowException(e);
+ } catch (NoSuchPaddingException e) {
+ rethrowException(e);
+ } catch (InvalidKeySpecException e) {
+ rethrowException(e);
+ } catch (InvalidKeyException e) {
+ rethrowException(e);
+ } catch (NoSuchProviderException e) {
+ rethrowException(e);
+ }
+ return null;
+ }
+
public static byte[] sign(KeyPair kp, byte value[]) throws CryptoException {
return sign(kp.getPrivate(), value);
***************
*** 675,678 ****
--- 703,710 ----
return asn1Bytes;
+ }
+
+ {
+ ensureProvider();
}
|