1 2 package jsdsi; 3 4 import java.security.KeyPair; 5 6 import jsdsi.Obj; 7 import jsdsi.util.DigestAlgoEnum; 8 import junit.framework.TestCase; 9 10 /*** 11 * Tests RSA key generation, signing, and verification. 12 * 13 * @author Sameer Ajmani 14 * @author Sean Radford 15 */ 16 public class SignatureTest extends TestCase { 17 public SignatureTest(String name) { 18 super(name); 19 } 20 21 public void testSignAndVerify() throws Exception { 22 KeyPair signer = jsdsi.RSAPublicKey.create(); 23 Obj signee = (jsdsi.RSAPublicKey) signer.getPublic(); 24 jsdsi.Signature sig = jsdsi.Signature.create(signer, 25 signee, 26 DigestAlgoEnum.MD5); 27 assertTrue("verification", sig.verify(signer.getPublic(), signee)); 28 } 29 30 public void testEquality() throws Exception { 31 KeyPair signer = jsdsi.RSAPublicKey.create(); 32 Obj signee = (jsdsi.RSAPublicKey) signer.getPublic(); 33 jsdsi.Signature sig = jsdsi.Signature.create(signer, 34 signee, 35 DigestAlgoEnum.MD5); 36 jsdsi.Signature sig2 = jsdsi.Signature.create(signer, 37 signee, 38 DigestAlgoEnum.MD5); 39 assertEquals("self equality", sig, sig); 40 assertEquals("equality", sig, sig2); 41 assertEquals("self hashcode equality", sig.hashCode(), sig.hashCode()); 42 assertEquals("hashcode equality", sig.hashCode(), sig2.hashCode()); 43 } 44 45 }

This page was automatically generated by Maven