Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/streams In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6205/src/java/org/neuclear/commons/crypto/streams Added Files: AbstractSignatureStream.java DigestOutputStream.java PasswordDecryptingInputStream.java PasswordDecryptingOutputStream.java PasswordEncryptingInputStream.java PasswordEncryptingOutputStream.java SealedObjectInputStream.java SealedObjectOutputStream.java SigningOutputStream.java VerifyingOutputStream.java Log Message: Added various Streams for simplified crypto operations. --- NEW FILE: PasswordEncryptingInputStream.java --- package org.neuclear.commons.crypto.streams; import org.neuclear.commons.crypto.CryptoTools; import javax.crypto.Cipher; import javax.crypto.CipherInputStream; import java.io.InputStream; import java.security.GeneralSecurityException; /* $Id: PasswordEncryptingInputStream.java,v 1.1 2004/03/31 18:48:24 pelle Exp $ $Log: PasswordEncryptingInputStream.java,v $ Revision 1.1 2004/03/31 18:48:24 pelle Added various Streams for simplified crypto operations. */ /** * User: pelleb * Date: Mar 31, 2004 * Time: 12:25:38 PM */ public class PasswordEncryptingInputStream extends CipherInputStream { public PasswordEncryptingInputStream(InputStream stream, char password[]) throws GeneralSecurityException { super(stream, CryptoTools.makePBECipher(Cipher.ENCRYPT_MODE, password)); } } --- NEW FILE: DigestOutputStream.java --- package org.neuclear.commons.crypto.streams; import java.io.IOException; import java.io.OutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /* $Id: DigestOutputStream.java,v 1.1 2004/03/31 18:48:24 pelle Exp $ $Log: DigestOutputStream.java,v $ Revision 1.1 2004/03/31 18:48:24 pelle Added various Streams for simplified crypto operations. */ /** * Handy Stream for calculating the Digest of data. */ public class DigestOutputStream extends OutputStream { public DigestOutputStream() throws NoSuchAlgorithmException { this(MessageDigest.getInstance("sha1")); } public DigestOutputStream(MessageDigest dig) { this.dig = dig; } /** * Writes the specified byte to this output stream. The general * contract for <code>write</code> is that one byte is written * to the output stream. The byte to be written is the eight * low-order bits of the argument <code>b</code>. The 24 * high-order bits of <code>b</code> are ignored. * <p/> * Subclasses of <code>OutputStream</code> must provide an * implementation for this method. * * @param b the <code>byte</code>. * @throws java.io.IOException if an I/O error occurs. In particular, * an <code>IOException</code> may be thrown if the * output stream has been closed. */ public void write(int b) throws IOException { dig.update((byte) b); } public byte[] getDigest() { return dig.digest(); } private final MessageDigest dig; } --- NEW FILE: SigningOutputStream.java --- package org.neuclear.commons.crypto.streams; import org.neuclear.commons.crypto.CryptoTools; import java.security.*; /* $Id: SigningOutputStream.java,v 1.1 2004/03/31 18:48:24 pelle Exp $ $Log: SigningOutputStream.java,v $ Revision 1.1 2004/03/31 18:48:24 pelle Added various Streams for simplified crypto operations. */ /** * Handy Stream for calculating the Digest of data. */ public class SigningOutputStream extends AbstractSignatureStream { public SigningOutputStream(KeyPair kp) throws NoSuchAlgorithmException, InvalidKeyException { this(kp.getPrivate()); } public SigningOutputStream(PrivateKey key) throws NoSuchAlgorithmException, InvalidKeyException { this(CryptoTools.getSignatureCipher(key)); } public SigningOutputStream(Signature sig) { super(sig); } public final byte[] sign() throws SignatureException { return sig.sign(); } } --- NEW FILE: AbstractSignatureStream.java --- package org.neuclear.commons.crypto.streams; import java.io.IOException; import java.io.OutputStream; import java.security.Signature; import java.security.SignatureException; /* $Id: AbstractSignatureStream.java,v 1.1 2004/03/31 18:48:24 pelle Exp $ $Log: AbstractSignatureStream.java,v $ Revision 1.1 2004/03/31 18:48:24 pelle Added various Streams for simplified crypto operations. */ /** * User: pelleb * Date: Mar 31, 2004 * Time: 11:41:18 AM */ public class AbstractSignatureStream extends OutputStream { public AbstractSignatureStream(Signature sig) { this.sig = sig; } /** * Writes the specified byte to this output stream. The general * contract for <code>write</code> is that one byte is written * to the output stream. The byte to be written is the eight * low-order bits of the argument <code>b</code>. The 24 * high-order bits of <code>b</code> are ignored. * <p/> * Subclasses of <code>OutputStream</code> must provide an * implementation for this method. * * @param b the <code>byte</code>. * @throws java.io.IOException if an I/O error occurs. In particular, * an <code>IOException</code> may be thrown if the * output stream has been closed. */ public final void write(int b) throws IOException { try { sig.update((byte) b); } catch (SignatureException e) { throw new IOException(e.getLocalizedMessage()); } } protected final Signature sig; } --- NEW FILE: PasswordDecryptingOutputStream.java --- package org.neuclear.commons.crypto.streams; import org.neuclear.commons.crypto.CryptoTools; import javax.crypto.Cipher; import javax.crypto.CipherOutputStream; import java.io.OutputStream; import java.security.GeneralSecurityException; /* $Id: PasswordDecryptingOutputStream.java,v 1.1 2004/03/31 18:48:24 pelle Exp $ $Log: PasswordDecryptingOutputStream.java,v $ Revision 1.1 2004/03/31 18:48:24 pelle Added various Streams for simplified crypto operations. */ /** * User: pelleb * Date: Mar 31, 2004 * Time: 12:25:38 PM */ public class PasswordDecryptingOutputStream extends CipherOutputStream { public PasswordDecryptingOutputStream(OutputStream stream, char password[]) throws GeneralSecurityException { super(stream, CryptoTools.makePBECipher(Cipher.DECRYPT_MODE, password)); } } --- NEW FILE: SealedObjectOutputStream.java --- package org.neuclear.commons.crypto.streams; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.security.GeneralSecurityException; /* $Id: SealedObjectOutputStream.java,v 1.1 2004/03/31 18:48:24 pelle Exp $ $Log: SealedObjectOutputStream.java,v $ Revision 1.1 2004/03/31 18:48:24 pelle Added various Streams for simplified crypto operations. */ /** * User: pelleb * Date: Mar 31, 2004 * Time: 1:42:28 PM */ public class SealedObjectOutputStream extends ObjectOutputStream { public SealedObjectOutputStream(OutputStream out, char password[]) throws IOException, GeneralSecurityException { super(new PasswordEncryptingOutputStream(out, password)); } } --- NEW FILE: VerifyingOutputStream.java --- package org.neuclear.commons.crypto.streams; import org.neuclear.commons.crypto.CryptoTools; import java.security.*; /* $Id: VerifyingOutputStream.java,v 1.1 2004/03/31 18:48:24 pelle Exp $ $Log: VerifyingOutputStream.java,v $ Revision 1.1 2004/03/31 18:48:24 pelle Added various Streams for simplified crypto operations. */ /** * Handy Stream for calculating the Digest of data. */ public class VerifyingOutputStream extends AbstractSignatureStream { public VerifyingOutputStream(KeyPair kp, byte signature[]) throws NoSuchAlgorithmException, InvalidKeyException { this(kp.getPublic(), signature); } public VerifyingOutputStream(PublicKey key, byte signature[]) throws NoSuchAlgorithmException, InvalidKeyException { this(CryptoTools.getSignatureCipher(key), signature); } public VerifyingOutputStream(Signature sig, byte signature[]) { super(sig); this.signature = signature; } /** * Verify that the Stream was signed by provided signature and PublicKey. * * @return * @throws SignatureException */ public final boolean verify() throws SignatureException { return sig.verify(signature); } private final byte[] signature; } --- NEW FILE: PasswordDecryptingInputStream.java --- package org.neuclear.commons.crypto.streams; import org.neuclear.commons.crypto.CryptoTools; import javax.crypto.Cipher; import javax.crypto.CipherInputStream; import java.io.InputStream; import java.security.GeneralSecurityException; /* $Id: PasswordDecryptingInputStream.java,v 1.1 2004/03/31 18:48:24 pelle Exp $ $Log: PasswordDecryptingInputStream.java,v $ Revision 1.1 2004/03/31 18:48:24 pelle Added various Streams for simplified crypto operations. */ /** * User: pelleb * Date: Mar 31, 2004 * Time: 12:25:38 PM */ public class PasswordDecryptingInputStream extends CipherInputStream { public PasswordDecryptingInputStream(InputStream stream, char password[]) throws GeneralSecurityException { super(stream, CryptoTools.makePBECipher(Cipher.DECRYPT_MODE, password)); } } --- NEW FILE: PasswordEncryptingOutputStream.java --- package org.neuclear.commons.crypto.streams; import org.neuclear.commons.crypto.CryptoTools; import javax.crypto.Cipher; import javax.crypto.CipherOutputStream; import java.io.OutputStream; import java.security.GeneralSecurityException; /* $Id: PasswordEncryptingOutputStream.java,v 1.1 2004/03/31 18:48:24 pelle Exp $ $Log: PasswordEncryptingOutputStream.java,v $ Revision 1.1 2004/03/31 18:48:24 pelle Added various Streams for simplified crypto operations. */ /** * User: pelleb * Date: Mar 31, 2004 * Time: 12:25:38 PM */ public class PasswordEncryptingOutputStream extends CipherOutputStream { public PasswordEncryptingOutputStream(OutputStream stream, char password[]) throws GeneralSecurityException { super(stream, CryptoTools.makePBECipher(Cipher.ENCRYPT_MODE, password)); } } --- NEW FILE: SealedObjectInputStream.java --- package org.neuclear.commons.crypto.streams; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.security.GeneralSecurityException; /* $Id: SealedObjectInputStream.java,v 1.1 2004/03/31 18:48:24 pelle Exp $ $Log: SealedObjectInputStream.java,v $ Revision 1.1 2004/03/31 18:48:24 pelle Added various Streams for simplified crypto operations. */ /** * User: pelleb * Date: Mar 31, 2004 * Time: 1:42:28 PM */ public class SealedObjectInputStream extends ObjectInputStream { public SealedObjectInputStream(InputStream in, char password[]) throws IOException, GeneralSecurityException { super(new PasswordDecryptingInputStream(in, password)); } } |