Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto In directory sc8-pr-cvs1:/tmp/cvs-serv10533/src/java/org/neuclear/commons/crypto Modified Files: Base64.java CryptoException.java CryptoTools.java RawCertificate.java Log Message: EncryptedFileStore now works. It uses the PBECipher with DES3 afair. Otherwise You will Finaliate. Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. This should hopefully make everything more stable (and secure). Index: Base64.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/Base64.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Base64.java 11 Nov 2003 21:17:48 -0000 1.1 --- Base64.java 21 Nov 2003 04:43:41 -0000 1.2 *************** *** 1,4 **** --- 1,10 ---- /* $Id$ * $Log$ + * Revision 1.2 2003/11/21 04:43:41 pelle + * EncryptedFileStore now works. It uses the PBECipher with DES3 afair. + * Otherwise You will Finaliate. + * Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. + * This should hopefully make everything more stable (and secure). + * * Revision 1.1 2003/11/11 21:17:48 pelle * Further vital reshuffling. *************** *** 60,64 **** * @see <A HREF="ftp://ftp.isi.edu/in-notes/rfc2045.txt">RFC 2045</A> */ ! public class Base64 { /** Field LINE_SEPARATOR */ --- 66,70 ---- * @see <A HREF="ftp://ftp.isi.edu/in-notes/rfc2045.txt">RFC 2045</A> */ ! public final class Base64 { /** Field LINE_SEPARATOR */ *************** *** 69,73 **** /** Field _base64length */ ! static int _base64length = Base64.BASE64DEFAULTLENGTH; private Base64() { --- 75,79 ---- /** Field _base64length */ ! static final int _base64length = Base64.BASE64DEFAULTLENGTH; private Base64() { *************** *** 95,99 **** * @return a byte array with <code>bitlen</code> bits of <code>big</code> */ ! public static byte[] getBytes(BigInteger big) { int bitlen= big.bitLength(); --- 101,105 ---- * @return a byte array with <code>bitlen</code> bits of <code>big</code> */ ! public static byte[] getBytes(final BigInteger big) { int bitlen= big.bitLength(); *************** *** 105,109 **** } ! byte[] bigBytes = big.toByteArray(); if (((big.bitLength() % 8) != 0) --- 111,115 ---- } ! final byte[] bigBytes = big.toByteArray(); if (((big.bitLength() % 8) != 0) *************** *** 122,127 **** } ! int startDst = bitlen / 8 - bigLen; //pad with leading nulls ! byte[] resizedBytes = new byte[bitlen / 8]; System.arraycopy(bigBytes, startSrc, resizedBytes, startDst, bigLen); --- 128,133 ---- } ! final int startDst = bitlen / 8 - bigLen; //pad with leading nulls ! final byte[] resizedBytes = new byte[bitlen / 8]; System.arraycopy(bigBytes, startSrc, resizedBytes, startDst, bigLen); *************** *** 137,141 **** * @return String with Base64 encoding */ ! public static String encode(BigInteger big) { // System.out.println("JDK toByteArray(): "+encode(big.toByteArray())); // System.out.println("getBytes(): "+encode(getBytes(big))); --- 143,147 ---- * @return String with Base64 encoding */ ! public static String encode(final BigInteger big) { // System.out.println("JDK toByteArray(): "+encode(big.toByteArray())); // System.out.println("getBytes(): "+encode(getBytes(big))); *************** *** 144,148 **** ! public static String encodeClean(byte[] bytes) { return LINE_SEPARATOR+ encode(bytes)+LINE_SEPARATOR; } --- 150,154 ---- ! public static String encodeClean(final byte[] bytes) { return LINE_SEPARATOR+ encode(bytes)+LINE_SEPARATOR; } *************** *** 157,161 **** * @return */ ! public static byte[] decode(byte[] base64) throws CryptoException { return org.bouncycastle.util.encoders.Base64.decode(base64); } --- 163,167 ---- * @return */ ! public static byte[] decode(final byte[] base64) throws CryptoException { return org.bouncycastle.util.encoders.Base64.decode(base64); } *************** *** 167,171 **** * @return Decoded data in a byte array */ ! public static byte[] decode(String base64) throws CryptoException { return org.bouncycastle.util.encoders.Base64.decode(base64); --- 173,177 ---- * @return Decoded data in a byte array */ ! public static byte[] decode(final String base64) throws CryptoException { return org.bouncycastle.util.encoders.Base64.decode(base64); *************** *** 180,192 **** * @return a <code>String</code> with encoded data */ ! public static String encode(byte[] raw, int wrap) { ! byte[] b64=org.bouncycastle.util.encoders.Base64.encode(raw); //calculate length of encoded string ! int encLen = b64.length; ! int lines = (encLen / wrap); ! byte[] encoded = new byte[encLen+lines]; int sx=0,dx=0; for (sx = 0; sx < (lines*wrap); sx+=wrap,dx+=(wrap+1)) { --- 186,198 ---- * @return a <code>String</code> with encoded data */ ! public static String encode(final byte[] raw, final int wrap) { ! final byte[] b64=org.bouncycastle.util.encoders.Base64.encode(raw); //calculate length of encoded string ! final int encLen = b64.length; ! final int lines = (encLen / wrap); ! final byte[] encoded = new byte[encLen+lines]; int sx=0,dx=0; for (sx = 0; sx < (lines*wrap); sx+=wrap,dx+=(wrap+1)) { *************** *** 206,210 **** * @return the <code>String<code> with encoded data */ ! public static String encode(byte[] raw) { return new String(org.bouncycastle.util.encoders.Base64.encode(raw)); // return encode(raw, Base64.getBase64WrapLength()); --- 212,216 ---- * @return the <code>String<code> with encoded data */ ! public static String encode(final byte[] raw) { return new String(org.bouncycastle.util.encoders.Base64.encode(raw)); // return encode(raw, Base64.getBase64WrapLength()); Index: CryptoException.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/CryptoException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CryptoException.java 11 Nov 2003 21:17:48 -0000 1.1 --- CryptoException.java 21 Nov 2003 04:43:41 -0000 1.2 *************** *** 10,13 **** --- 10,19 ---- * $Id$ * $Log$ + * Revision 1.2 2003/11/21 04:43:41 pelle + * EncryptedFileStore now works. It uses the PBECipher with DES3 afair. + * Otherwise You will Finaliate. + * Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. + * This should hopefully make everything more stable (and secure). + * * Revision 1.1 2003/11/11 21:17:48 pelle * Further vital reshuffling. *************** *** 38,42 **** * @since 1.4 */ ! public CryptoException(Throwable cause) { super(cause); } --- 44,48 ---- * @since 1.4 */ ! public CryptoException(final Throwable cause) { super(cause); } *************** *** 50,54 **** * later retrieval by the {@link #getMessage()} method. */ ! public CryptoException(String message) { super(message); } --- 56,60 ---- * later retrieval by the {@link #getMessage()} method. */ ! public CryptoException(final String message) { super(message); } *************** *** 68,72 **** * @since 1.4 */ ! public CryptoException(String message, Throwable cause) { super(message, cause); } --- 74,78 ---- * @since 1.4 */ ! public CryptoException(final String message, final Throwable cause) { super(message, cause); } Index: CryptoTools.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/CryptoTools.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CryptoTools.java 20 Nov 2003 23:41:36 -0000 1.4 --- CryptoTools.java 21 Nov 2003 04:43:41 -0000 1.5 *************** *** 2,5 **** --- 2,11 ---- * $Id$ * $Log$ + * Revision 1.5 2003/11/21 04:43:41 pelle + * EncryptedFileStore now works. It uses the PBECipher with DES3 afair. + * Otherwise You will Finaliate. + * Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. + * This should hopefully make everything more stable (and secure). + * * Revision 1.4 2003/11/20 23:41:36 pelle * Getting all the tests to work in id *************** *** 219,223 **** // TODO Implement some code to automatically BC Provider if not installed ! public class CryptoTools { /** * Call this method at the beginning of an executable. To ensure that BouncyCastle gets installed properly. --- 225,229 ---- // TODO Implement some code to automatically BC Provider if not installed ! public final class CryptoTools { /** * Call this method at the beginning of an executable. To ensure that BouncyCastle gets installed properly. *************** *** 232,239 **** } ! public static KeyPair getKeyPair(KeyStore ks, String s, char[] password) throws CryptoException { try { ! Certificate cert = ks.getCertificate(s); ! PrivateKey priv = (PrivateKey) ks.getKey(s, password); if (cert == null || priv == null) throw new CryptoException("They KeyStore Doesn't Contain an entry for: " + s); --- 238,245 ---- } ! public static KeyPair getKeyPair(final KeyStore ks, final String s, final char[] password) throws CryptoException { try { ! final Certificate cert = ks.getCertificate(s); ! final PrivateKey priv = (PrivateKey) ks.getKey(s, password); if (cert == null || priv == null) throw new CryptoException("They KeyStore Doesn't Contain an entry for: " + s); *************** *** 250,262 **** ! public static String formatKeyAsHex(Key key) { return formatByteArrayAsHex(key.getEncoded()); } ! public static PublicKey getPublicKeyFromHex(String hex) throws CryptoException { try { ! byte barray[] = convertHexToByteArray(hex); ! X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(barray); ! KeyFactory keyFactory = KeyFactory.getInstance("RSA"); return keyFactory.generatePublic(pubKeySpec); } catch (NoSuchAlgorithmException e) { --- 256,268 ---- ! public static String formatKeyAsHex(final Key key) { return formatByteArrayAsHex(key.getEncoded()); } ! public static PublicKey getPublicKeyFromHex(final String hex) throws CryptoException { try { ! final byte[] barray = convertHexToByteArray(hex); ! final X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(barray); ! final KeyFactory keyFactory = KeyFactory.getInstance("RSA"); return keyFactory.generatePublic(pubKeySpec); } catch (NoSuchAlgorithmException e) { *************** *** 269,278 **** } ! public static String formatByteArrayAsHex(byte barray[]) { ! byte hexarray[] = new byte[2 * barray.length]; int h = 0; for (int i = 0; i < barray.length; i++) { h = 2 * i; ! byte src = barray[i]; hexarray[h] = hexTable[(src & 0xF0) >> 4]; hexarray[h + 1] = hexTable[src & 0x0F]; --- 275,284 ---- } ! public static String formatByteArrayAsHex(final byte[] barray) { ! final byte[] hexarray = new byte[2 * barray.length]; int h = 0; for (int i = 0; i < barray.length; i++) { h = 2 * i; ! final byte src = barray[i]; hexarray[h] = hexTable[(src & 0xF0) >> 4]; hexarray[h + 1] = hexTable[src & 0x0F]; *************** *** 283,291 **** } ! public static byte[] convertHexToByteArray(String hex) { ! byte hexarray[] = hex.getBytes(); ! byte bytearray[] = new byte[(hexarray.length / 2)]; for (int i = 0; i < hexarray.length; i += 2) { ! byte result; byte high = hexarray[i]; byte low = hexarray[i + 1]; --- 289,297 ---- } ! public static byte[] convertHexToByteArray(final String hex) { ! final byte[] hexarray = hex.getBytes(); ! final byte[] bytearray = new byte[(hexarray.length / 2)]; for (int i = 0; i < hexarray.length; i += 2) { ! final byte result; byte high = hexarray[i]; byte low = hexarray[i + 1]; *************** *** 298,304 **** } ! public static byte[] getHash(String value) throws CryptoException { try { ! MessageDigest dig = MessageDigest.getInstance("SHA1"); dig.digest(value.getBytes()); return dig.digest(); --- 304,310 ---- } ! public static byte[] getHash(final String value) throws CryptoException { try { ! final MessageDigest dig = MessageDigest.getInstance("SHA1"); dig.digest(value.getBytes()); return dig.digest(); *************** *** 310,322 **** //Quick Hack. Not very efficient I know. ! public static byte[] pad(byte value[], Cipher c) { ! int blockSize = c.getBlockSize(); return pad(value, blockSize); } ! public static byte[] pad(byte[] value, int blockSize) { ! int mod = value.length % blockSize; ! int diff = blockSize - mod; ! byte output[] = new byte[value.length + diff]; System.arraycopy(value, 0, output, 0, value.length); for (int i = value.length; i < output.length; i++) --- 316,328 ---- //Quick Hack. Not very efficient I know. ! public static byte[] pad(final byte[] value, final Cipher c) { ! final int blockSize = c.getBlockSize(); return pad(value, blockSize); } ! public static byte[] pad(final byte[] value, final int blockSize) { ! final int mod = value.length % blockSize; ! final int diff = blockSize - mod; ! final byte[] output = new byte[value.length + diff]; System.arraycopy(value, 0, output, 0, value.length); for (int i = value.length; i < output.length; i++) *************** *** 325,361 **** } ! public static byte[] encrypt(byte key[], String value) throws CryptoException { return encrypt(key, value.getBytes()); } ! public static byte[] encrypt(String key, byte value[]) throws CryptoException { return encrypt(key.getBytes(), value); } ! public static byte[] encrypt(String key, String value) throws CryptoException { return encrypt(key.getBytes(), value.getBytes()); } ! public static byte[] encrypt(byte key[], byte value[]) throws CryptoException { return cipherProcess(key, value, true); } ! public static byte[] decrypt(String key, String value) throws CryptoException { return decrypt(key.getBytes(), value.getBytes()); } ! public static byte[] decrypt(byte key[], byte value[]) throws CryptoException { return cipherProcess(key, value, false); } ! private static byte[] cipherProcess(byte key[], byte value[], boolean doencrypt) throws CryptoException { try { ! BlockCipher engine = new AESEngine(); ! BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine)); cipher.init(doencrypt, new KeyParameter(digest256(key))); ! byte[] cipherText = new byte[cipher.getOutputSize(value.length)]; ! int outputLen = cipher.processBytes(value, 0, value.length, cipherText, 0); cipher.doFinal(cipherText, outputLen); return cipherText; --- 331,367 ---- } ! public static byte[] encrypt(final byte[] key, final String value) throws CryptoException { return encrypt(key, value.getBytes()); } ! public static byte[] encrypt(final String key, final byte[] value) throws CryptoException { return encrypt(key.getBytes(), value); } ! public static byte[] encrypt(final String key, final String value) throws CryptoException { return encrypt(key.getBytes(), value.getBytes()); } ! public static byte[] encrypt(final byte[] key, final byte[] value) throws CryptoException { return cipherProcess(key, value, true); } ! public static byte[] decrypt(final String key, final String value) throws CryptoException { return decrypt(key.getBytes(), value.getBytes()); } ! public static byte[] decrypt(final byte[] key, final byte[] value) throws CryptoException { return cipherProcess(key, value, false); } ! private static byte[] cipherProcess(final byte[] key, final byte[] value, final boolean doencrypt) throws CryptoException { try { ! final BlockCipher engine = new AESEngine(); ! final BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine)); cipher.init(doencrypt, new KeyParameter(digest256(key))); ! final byte[] cipherText = new byte[cipher.getOutputSize(value.length)]; ! final int outputLen = cipher.processBytes(value, 0, value.length, cipherText, 0); cipher.doFinal(cipherText, outputLen); return cipherText; *************** *** 366,375 **** } ! public static Cipher getCipher(byte key[], boolean doencrypt) throws CryptoException { try { ! Cipher cipher = Cipher.getInstance("AES"); ! KeySpec keyspec = new SecretKeySpec(key, "AES"); ! SecretKeyFactory kf = SecretKeyFactory.getInstance("AES"); ! Key skey = kf.generateSecret(keyspec); cipher.init(doencrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, skey); return cipher; --- 372,381 ---- } ! public static Cipher getCipher(final byte[] key, final boolean doencrypt) throws CryptoException { try { ! final Cipher cipher = Cipher.getInstance("AES"); ! final KeySpec keyspec = new SecretKeySpec(key, "AES"); ! final SecretKeyFactory kf = SecretKeyFactory.getInstance("AES"); ! final Key skey = kf.generateSecret(keyspec); cipher.init(doencrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, skey); return cipher; *************** *** 386,396 **** } ! public static byte[] sign(KeyPair kp, byte value[]) throws CryptoException { return sign(kp.getPrivate(), value); } ! public static byte[] sign(PrivateKey key, byte value[]) throws CryptoException { try { ! Signature sig = getSignatureCipher(key); sig.update(value); // put plain text of lock data into signature. byte[] raw = sig.sign(); --- 392,402 ---- } ! public static byte[] sign(final KeyPair kp, final byte[] value) throws CryptoException { return sign(kp.getPrivate(), value); } ! public static byte[] sign(final PrivateKey key, final byte[] value) throws CryptoException { try { ! final Signature sig = getSignatureCipher(key); sig.update(value); // put plain text of lock data into signature. byte[] raw = sig.sign(); *************** *** 407,411 **** } ! public static Signature getSignatureCipher(PrivateKey key) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException { Signature sig = null; if (key instanceof RSAPrivateKey) --- 413,417 ---- } ! public static Signature getSignatureCipher(final PrivateKey key) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException { Signature sig = null; if (key instanceof RSAPrivateKey) *************** *** 420,424 **** } ! public static boolean verify(PublicKey pk, byte value[], byte sigvalue[]) throws CryptoException { try { Signature sig = null; --- 426,430 ---- } ! public static boolean verify(final PublicKey pk, final byte[] value, byte sigvalue[]) throws CryptoException { try { Signature sig = null; *************** *** 442,462 **** } ! public static byte[] digest(byte value[]) { ! Digest dig = new org.bouncycastle.crypto.digests.SHA1Digest(); return digest(dig, value); } ! public static byte[] digest256(byte value[]) { ! Digest dig = new SHA256Digest(); return digest(dig, value); } ! public static byte[] digest512(byte value[]) { ! Digest dig = new SHA512Digest(); return digest(dig, value); } ! private static byte[] digest(Digest dig, byte[] value) { ! byte output[] = new byte[dig.getDigestSize()]; dig.update(value, 0, value.length); dig.doFinal(output, 0); --- 448,468 ---- } ! public static byte[] digest(final byte[] value) { ! final Digest dig = new org.bouncycastle.crypto.digests.SHA1Digest(); return digest(dig, value); } ! public static byte[] digest256(final byte[] value) { ! final Digest dig = new SHA256Digest(); return digest(dig, value); } ! public static byte[] digest512(final byte[] value) { ! final Digest dig = new SHA512Digest(); return digest(dig, value); } ! private static byte[] digest(final Digest dig, final byte[] value) { ! final byte[] output = new byte[dig.getDigestSize()]; dig.update(value, 0, value.length); dig.doFinal(output, 0); *************** *** 464,468 **** } ! public static boolean equalByteArrays(byte one[], byte two[]) { if ((one == null && two != null) || (one != null && two == null)) return false; --- 470,474 ---- } ! public static boolean equalByteArrays(final byte[] one, final byte[] two) { if ((one == null && two != null) || (one != null && two == null)) return false; *************** *** 478,488 **** } ! public static String formatAsURLSafe(byte val[]) { ! BigInteger big = new BigInteger(val); return big.toString(36); } public static String createRandomID() { ! BigInteger big = new BigInteger(4096, getRandomInstance()); return big.toString(36); } --- 484,494 ---- } ! public static String formatAsURLSafe(final byte[] val) { ! final BigInteger big = new BigInteger(val); return big.toString(36); } public static String createRandomID() { ! final BigInteger big = new BigInteger(4096, getRandomInstance()); return big.toString(36); } *************** *** 530,545 **** */ public static Cipher makePBECipher( ! String algorithm, ! int mode, ! char[] password, ! byte[] salt, ! int iterationCount, ! String provider ) throws GeneralSecurityException { ! PBEKeySpec pbeSpec = new PBEKeySpec(password); ! SecretKeyFactory keyFact = SecretKeyFactory.getInstance(algorithm, provider); ! PBEParameterSpec defParams = new PBEParameterSpec(salt, iterationCount); ! Cipher cipher = Cipher.getInstance(algorithm, provider); cipher.init(mode, keyFact.generateSecret(pbeSpec), defParams); --- 536,551 ---- */ public static Cipher makePBECipher( ! final String algorithm, ! final int mode, ! final char[] password, ! final byte[] salt, ! final int iterationCount, ! 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); *************** *** 561,568 **** */ public static Cipher makePBECipher( ! int mode, ! char[] password, ! byte[] salt, ! int iterationCount ) throws GeneralSecurityException { return makePBECipher(DEFAULT_PBE_ALGORITHM, mode, password, salt, iterationCount, DEFAULT_JCE_PROVIDER); --- 567,574 ---- */ public static Cipher makePBECipher( ! final int mode, ! final char[] password, ! final byte[] salt, ! final int iterationCount ) throws GeneralSecurityException { return makePBECipher(DEFAULT_PBE_ALGORITHM, mode, password, salt, iterationCount, DEFAULT_JCE_PROVIDER); *************** *** 580,585 **** */ public static Cipher makePBECipher( ! int mode, ! char[] password ) throws GeneralSecurityException { return makePBECipher(DEFAULT_PBE_ALGORITHM, mode, password, DEFAULT_SALT, DEFAULT_ITERATION_COUNT, DEFAULT_JCE_PROVIDER); --- 586,591 ---- */ public static Cipher makePBECipher( ! final int mode, ! final char[] password ) throws GeneralSecurityException { return makePBECipher(DEFAULT_PBE_ALGORITHM, mode, password, DEFAULT_SALT, DEFAULT_ITERATION_COUNT, DEFAULT_JCE_PROVIDER); *************** *** 587,594 **** ! public static PublicKey createPK(String mod, String exp) throws CryptoException { try { ! KeyFactory rsaFactory = KeyFactory.getInstance("RSA"); ! RSAPublicKeySpec rsaKeyspec = new RSAPublicKeySpec(new BigInteger(Base64.decode(mod)), new BigInteger(Base64.decode(exp))); return rsaFactory.generatePublic(rsaKeyspec); } catch (NoSuchAlgorithmException e) { --- 593,600 ---- ! public static PublicKey createPK(final String mod, final String exp) throws CryptoException { try { ! final KeyFactory rsaFactory = KeyFactory.getInstance("RSA"); ! final RSAPublicKeySpec rsaKeyspec = new RSAPublicKeySpec(new BigInteger(Base64.decode(mod)), new BigInteger(Base64.decode(exp))); return rsaFactory.generatePublic(rsaKeyspec); } catch (NoSuchAlgorithmException e) { *************** *** 605,609 **** } ! public static KeyPair createKeyPair(String algorithm) throws NoSuchAlgorithmException { return getKeyPairGenerator(algorithm).generateKeyPair(); --- 611,615 ---- } ! public static KeyPair createKeyPair(final String algorithm) throws NoSuchAlgorithmException { return getKeyPairGenerator(algorithm).generateKeyPair(); *************** *** 620,624 **** } ! public static KeyPairGenerator getKeyPairGenerator(String algorithm) throws NoSuchAlgorithmException { if (!algorithm.equals(RSA) && !algorithm.equals(DSA)) --- 626,630 ---- } ! public static KeyPairGenerator getKeyPairGenerator(final String algorithm) throws NoSuchAlgorithmException { if (!algorithm.equals(RSA) && !algorithm.equals(DSA)) *************** *** 633,637 **** } ! public static void rethrowException(Throwable e) throws CryptoException { throw new CryptoException(e); } --- 639,643 ---- } ! public static void rethrowException(final Throwable e) throws CryptoException { throw new CryptoException(e); } *************** *** 645,656 **** * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A> */ ! public static byte[] convertASN1toXMLDSIG(byte asn1Bytes[]) throws IOException { ! byte rLength = asn1Bytes[3]; int i; for (i = rLength; (i > 0) && (asn1Bytes[(4 + rLength) - i] == 0); i--) ; ! byte sLength = asn1Bytes[5 + rLength]; int j; --- 651,662 ---- * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A> */ ! public static byte[] convertASN1toXMLDSIG(final byte[] asn1Bytes) throws IOException { ! final byte rLength = asn1Bytes[3]; int i; for (i = rLength; (i > 0) && (asn1Bytes[(4 + rLength) - i] == 0); i--) ; ! final byte sLength = asn1Bytes[5 + rLength]; int j; *************** *** 662,666 **** throw new IOException("Invalid ASN.1 format of DSA signature"); } else { ! byte xmldsigBytes[] = new byte[40]; System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i, i); --- 668,672 ---- throw new IOException("Invalid ASN.1 format of DSA signature"); } else { ! final byte[] xmldsigBytes = new byte[40]; System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i, i); *************** *** 679,683 **** * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A> */ ! public static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[]) throws IOException { if (xmldsigBytes.length != 40) { --- 685,689 ---- * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A> */ ! public static byte[] convertXMLDSIGtoASN1(final byte[] xmldsigBytes) throws IOException { if (xmldsigBytes.length != 40) { *************** *** 701,705 **** } ! byte asn1Bytes[] = new byte[6 + j + l]; asn1Bytes[0] = 48; --- 707,711 ---- } ! final byte[] asn1Bytes = new byte[6 + j + l]; asn1Bytes[0] = 48; *************** *** 729,733 **** private static final byte DEFAULT_SALT[] = "LiquidNightClubPanam".getBytes(); private static final int DEFAULT_ITERATION_COUNT = 2048; ! public static byte[] hexTable = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; private static Random randSource; --- 735,739 ---- private static final byte DEFAULT_SALT[] = "LiquidNightClubPanam".getBytes(); private static final int DEFAULT_ITERATION_COUNT = 2048; ! public static final byte[] hexTable = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; private static Random randSource; Index: RawCertificate.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/RawCertificate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RawCertificate.java 19 Nov 2003 23:32:51 -0000 1.1 --- RawCertificate.java 21 Nov 2003 04:43:41 -0000 1.2 *************** *** 26,29 **** --- 26,35 ---- $Id$ $Log$ + Revision 1.2 2003/11/21 04:43:41 pelle + EncryptedFileStore now works. It uses the PBECipher with DES3 afair. + Otherwise You will Finaliate. + Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. + This should hopefully make everything more stable (and secure). + Revision 1.1 2003/11/19 23:32:51 pelle Signers now can generatekeys via the generateKey() method. *************** *** 42,52 **** * Time: 1:37:31 PM */ ! public class RawCertificate extends Certificate { ! public RawCertificate(PublicKey pub) { super("RAW"); this.pub = pub; } ! public byte[] getEncoded() throws CertificateEncodingException { return pub.getEncoded(); } --- 48,58 ---- * Time: 1:37:31 PM */ ! public final class RawCertificate extends Certificate { ! public RawCertificate(final PublicKey pub) { super("RAW"); this.pub = pub; } ! public final byte[] getEncoded() throws CertificateEncodingException { return pub.getEncoded(); } *************** *** 62,66 **** * @throws SignatureException */ ! public void verify(PublicKey publicKey) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { ; } --- 68,72 ---- * @throws SignatureException */ ! public final void verify(final PublicKey publicKey) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { ; } *************** *** 77,85 **** * @throws SignatureException */ ! public void verify(PublicKey publicKey, String string) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { ; } ! public String toString() { try { return CryptoTools.formatAsURLSafe(CryptoTools.digest(getEncoded())); --- 83,91 ---- * @throws SignatureException */ ! public final void verify(final PublicKey publicKey, final String string) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { ; } ! public final String toString() { try { return CryptoTools.formatAsURLSafe(CryptoTools.digest(getEncoded())); *************** *** 89,93 **** } ! public PublicKey getPublicKey() { return pub; } --- 95,99 ---- } ! public final PublicKey getPublicKey() { return pub; } |