|
From: Pelle B. <pe...@us...> - 2004-04-09 20:16:17
|
Update of /cvsroot/neuclear/neuclear-commons/src/test/org/neuclear/commons/crypto In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4281/src/test/org/neuclear/commons/crypto Modified Files: CryptoToolsTest.java Log Message: Added PrivateKey wrapping and unwrapping to CryptoTools with the methods: byte [] wrapKey(char passphrase[], PrivateKey key) and PrivateKey unWrapKey(char passphrase[],byte wrapped[],String algorithm) PrivateKey unWrapRSAKey(char passphrase[],byte wrapped[]) Index: CryptoToolsTest.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/test/org/neuclear/commons/crypto/CryptoToolsTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CryptoToolsTest.java 21 Nov 2003 04:43:42 -0000 1.2 --- CryptoToolsTest.java 9 Apr 2004 20:02:55 -0000 1.3 *************** *** 2,5 **** --- 2,12 ---- $Id$ $Log$ + Revision 1.3 2004/04/09 20:02:55 pelle + Added PrivateKey wrapping and unwrapping to CryptoTools with the methods: + byte [] wrapKey(char passphrase[], PrivateKey key) + and + PrivateKey unWrapKey(char passphrase[],byte wrapped[],String algorithm) + PrivateKey unWrapRSAKey(char passphrase[],byte wrapped[]) + Revision 1.2 2003/11/21 04:43:42 pelle EncryptedFileStore now works. It uses the PBECipher with DES3 afair. *************** *** 92,96 **** import junit.framework.TestCase; import junit.framework.TestSuite; ! import org.neuclear.commons.NeuClearException; --- 99,106 ---- import junit.framework.TestCase; import junit.framework.TestSuite; ! ! import java.security.KeyPair; ! import java.security.NoSuchAlgorithmException; ! import java.security.PrivateKey; *************** *** 132,136 **** } ! public final void testSymmetricKeyEncryption() throws CryptoException { final String contentString = "<xml>Hello</xml>"; final byte[] password = "Three Brown Geese sledded down the hill".getBytes(); --- 142,146 ---- } ! public final void testSymmetricKeyEncryption() throws CryptoException { final String contentString = "<xml>Hello</xml>"; final byte[] password = "Three Brown Geese sledded down the hill".getBytes(); *************** *** 149,152 **** --- 159,176 ---- } + public final void testKeyWrapping() throws NoSuchAlgorithmException, CryptoException { + KeyPair kp = CryptoTools.createTinyRSAKeyPair(); + assertNotNull(kp); + assertNotNull(kp.getPrivate()); + char password[] = "the secrets of the world are mine".toCharArray(); + byte wrapped[] = CryptoTools.wrapKey(password, kp.getPrivate()); + assertNotNull(wrapped); + PrivateKey priv = CryptoTools.unWrapRSAKey(password, wrapped); + + byte[] data = "the quick brown fox jumped over the lazy dog".getBytes(); + byte[] sig = CryptoTools.sign(priv, data); + assertNotNull(sig); + assertTrue(CryptoTools.verify(kp.getPublic(), data, sig)); + } } |