|
From: Pelle B. <pe...@us...> - 2004-03-31 19:00:54
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6205/src/java/org/neuclear/commons/crypto Modified Files: CryptoTools.java Log Message: Added various Streams for simplified crypto operations. Index: CryptoTools.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/CryptoTools.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** CryptoTools.java 19 Mar 2004 22:21:24 -0000 1.18 --- CryptoTools.java 31 Mar 2004 18:48:25 -0000 1.19 *************** *** 2,5 **** --- 2,8 ---- * $Id$ * $Log$ + * Revision 1.19 2004/03/31 18:48:25 pelle + * Added various Streams for simplified crypto operations. + * * Revision 1.18 2004/03/19 22:21:24 pelle * Changes in the XMLSignature class, which is now Abstract there are currently 3 implementations for: *************** *** 260,263 **** --- 263,267 ---- import org.bouncycastle.jce.X509V3CertificateGenerator; import org.bouncycastle.jce.interfaces.ECPrivateKey; + import org.bouncycastle.jce.interfaces.ECPublicKey; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.neuclear.commons.time.TimeTools; *************** *** 497,500 **** --- 501,517 ---- } + public static Signature getSignatureCipher(final PublicKey key) throws NoSuchAlgorithmException, InvalidKeyException { + Signature sig = null; + if (key instanceof RSAPublicKey) + sig = Signature.getInstance("SHA1withRSA"); // Set up signature object. + else if (key instanceof DSAPublicKey) + sig = Signature.getInstance("SHA1withDSA"); + else if (key instanceof ECPublicKey) + sig = Signature.getInstance("SHA1withECDSA"); + + sig.initVerify(key); // Initialize with my public key. + return sig; + } + public static boolean verify(final PublicKey pk, final byte[] value, byte sigvalue[]) throws CryptoException { try { *************** *** 643,650 **** final String provider) throws GeneralSecurityException { final PBEKeySpec pbeSpec = new PBEKeySpec(password); ! final SecretKeyFactory keyFact = SecretKeyFactory.getInstance(algorithm, provider); final PBEParameterSpec defParams = new PBEParameterSpec(salt, iterationCount); ! final Cipher cipher = Cipher.getInstance(algorithm, provider); cipher.init(mode, keyFact.generateSecret(pbeSpec), defParams); --- 660,667 ---- final String provider) throws GeneralSecurityException { final PBEKeySpec pbeSpec = new PBEKeySpec(password); ! final SecretKeyFactory keyFact = SecretKeyFactory.getInstance(algorithm); final PBEParameterSpec defParams = new PBEParameterSpec(salt, iterationCount); ! final Cipher cipher = Cipher.getInstance(algorithm); cipher.init(mode, keyFact.generateSecret(pbeSpec), defParams); *************** *** 876,882 **** private static KeyPairGenerator tkg; private static KeyPairGenerator tdkg; ! public static final String DEFAULT_PBE_ALGORITHM = "PBEWithSHAAnd3-KeyTripleDES-CBC"; public static final String DEFAULT_JCE_PROVIDER = "BC"; ! private static final byte DEFAULT_SALT[] = "LiquidNightClubPanam".getBytes(); private static final int DEFAULT_ITERATION_COUNT = 2048; private static final byte[] HEX_TABLE = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; --- 893,899 ---- private static KeyPairGenerator tkg; private static KeyPairGenerator tdkg; ! public static final String DEFAULT_PBE_ALGORITHM = "PBEWithMD5AndDES"; public static final String DEFAULT_JCE_PROVIDER = "BC"; ! private static final byte DEFAULT_SALT[] = "LiquidNi".getBytes(); private static final int DEFAULT_ITERATION_COUNT = 2048; private static final byte[] HEX_TABLE = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; |