1 21 22 package net.sourceforge.jcetaglib.test; 23 24 import junit.framework.Assert; 25 import junit.framework.TestCase; 26 import net.sourceforge.jcetaglib.lib.Signatures; 27 import net.sourceforge.jcetaglib.lib.X509Cert; 28 29 import java.io.DataOutputStream ; 30 import java.io.FileOutputStream ; 31 import java.io.IOException ; 32 import java.security.PrivateKey ; 33 import java.security.cert.X509Certificate ; 34 35 45 public class SignatureTest extends TestCase { 46 private StringBuffer sig = null; 47 48 53 protected void setUp() throws IOException { 54 FileOutputStream outStr = new FileOutputStream (RunTest.TEMPFOLDER + "readable.txt"); 56 DataOutputStream dataStr = new DataOutputStream (outStr); 57 58 dataStr.writeBytes("This is a readable string inside a file"); 59 60 dataStr.flush(); 61 dataStr.close(); 62 63 outStr.close(); 64 } 65 66 71 public void testSignature() throws Exception { 72 X509Certificate alicecert = X509Cert.getCertificateFromP12(RunTest.TEMPFOLDER + "alice.p12", "alice", new StringBuffer ("password")); 74 75 PrivateKey aliceprivate = X509Cert.getPrivateFromP12(RunTest.TEMPFOLDER + "alice.p12", "alice", new StringBuffer ("password")); 77 78 for (int i = 0; i < RunTest.sig.length; i++) { 79 for (int j = 0; j < RunTest.text.length; j++) { 80 sig = Signatures.generateSIG(RunTest.text[j], aliceprivate, RunTest.sig[i]); 81 82 Assert.assertTrue(Signatures.verifySIG(RunTest.text[j], sig, alicecert.getPublicKey(), RunTest.sig[i])); 83 } 84 } 85 } 86 87 92 public void testFileSignature() throws Exception { 93 X509Certificate alicecert = X509Cert.getCertificateFromP12(RunTest.TEMPFOLDER + "alice.p12", "alice", new StringBuffer ("password")); 95 96 PrivateKey aliceprivate = X509Cert.getPrivateFromP12(RunTest.TEMPFOLDER + "alice.p12", "alice", new StringBuffer ("password")); 98 99 for (int i = 0; i < RunTest.sig.length; i++) { 100 sig = Signatures.generateFileSIG(RunTest.TEMPFOLDER + "readable.txt", aliceprivate, RunTest.sig[i]); 101 102 Assert.assertTrue(Signatures.verifyFileSIG(RunTest.TEMPFOLDER + "readable.txt", sig, alicecert.getPublicKey(), RunTest.sig[i])); 103 } 104 } 105 } 106 | Popular Tags |