KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > lightcrypto > test > HMacTest


1 package net.sourceforge.lightcrypto.test;
2
3 import junit.framework.Assert;
4 import junit.framework.TestCase;
5 import net.sourceforge.lightcrypto.HMacs;
6
7 import java.io.DataOutputStream JavaDoc;
8 import java.io.FileOutputStream JavaDoc;
9 import java.io.IOException JavaDoc;
10
11 /**
12  * A collection of HMAC tests
13  * <P>
14  * These tests can be run using JUnit (http://www.junit.org)
15  *
16  * @author Gert Van Ham
17  * @author hamgert@users.sourceforge.net
18  * @author http://jcetaglib.sourceforge.net
19  * @version $Id: HMacTest.java,v 1.1 2003/10/05 11:41:29 hamgert Exp $
20  */

21
22 public class HMacTest extends TestCase {
23      private StringBuffer JavaDoc text1;
24      private StringBuffer JavaDoc text2;
25      private StringBuffer JavaDoc text3;
26      private StringBuffer JavaDoc text4;
27      private StringBuffer JavaDoc text5;
28      private StringBuffer JavaDoc text6;
29      private StringBuffer JavaDoc text7;
30      private StringBuffer JavaDoc text8;
31      private StringBuffer JavaDoc text9;
32      private StringBuffer JavaDoc text10;
33
34     /**
35      * setup test
36      *
37      * @throws java.io.IOException
38      */

39      protected void setUp() throws IOException JavaDoc {
40          text1= new StringBuffer JavaDoc("The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms");
41          text2= new StringBuffer JavaDoc("This software is distributed under a license based on the MIT X Consortium license");
42          text3= new StringBuffer JavaDoc("found in $JAVA_HOME/jre/lib/security/java.security, where $JAVA_HOME is the location of your JDK/JRE distribution");
43          text4= new StringBuffer JavaDoc("Mit Project 2002 zum erfolgreichen Projektmanagement Damit Sie in Zukunft Ihre Projekte präzise und komfortabel steuern können");
44          text5= new StringBuffer JavaDoc("En av de största nyheterna är att det finns en .NET Enterprise Server-lösning för stora företagsomspännade projekt");
45          text6= new StringBuffer JavaDoc("Lees de productinformatie en ontdek alles over de krachtige tools binnen Visual Studio .NET");
46          text7= new StringBuffer JavaDoc("Vergeet even die oude tovenaars met puntige hoeden en rondborstige jonkvrouwen in nood... oké, vergeet in ieder geval even die tovenaars, want Lionheart komt met een ambitieuze rollenspelvariant");
47          text8= new StringBuffer JavaDoc("An implementation of ECIES (stream mode) as described in IEEE P 1363a.");
48          text9= new StringBuffer JavaDoc("This makes the entire keystore resistant to tampering and inspection, and forces verification");
49          text10= new StringBuffer JavaDoc("application/pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_signature");
50
51          // create text file
52
FileOutputStream JavaDoc outStr = new FileOutputStream JavaDoc(RunTest.TEMPFOLDER + "readable.txt");
53         DataOutputStream JavaDoc dataStr = new DataOutputStream JavaDoc(outStr);
54
55         dataStr.writeBytes("This is a readable string inside a file");
56
57         dataStr.flush();
58         dataStr.close();
59
60         outStr.close();
61      }
62
63     /**
64      * test HMAC
65      *
66      * @throws Exception
67      */

68      public void testHmac() throws Exception JavaDoc {
69         Assert.assertEquals(HMacs.mac(text1).toString(),"PhX3UR5UV8g2JSwzaIMhmbbGzcs=");
70         Assert.assertEquals(HMacs.mac(text2).toString(),"xLlNhfjrcyl6rOmDUDDdaxYBVeA=");
71         Assert.assertEquals(HMacs.mac(text3).toString(),"YBmWah8XC1DaMz6z+5XJIAfaU/A=");
72         Assert.assertEquals(HMacs.mac(text4).toString(),"F3uuSWd1wy+nzed0i8/HU1Qw7iw=");
73         Assert.assertEquals(HMacs.mac(text5).toString(),"cCa/XPXAEi1wlxgObcjiYkTxU+w=");
74         Assert.assertEquals(HMacs.mac(text6).toString(),"6xkWTygLs3nyKLPkQqQeEXgBJ98=");
75         Assert.assertEquals(HMacs.mac(text7).toString(),"ag9+ZfwJDzeYiXbSFrCGT/cTs3M=");
76         Assert.assertEquals(HMacs.mac(text8).toString(),"AeC346vUfMYmD4v5LeMdbPvixkU=");
77         Assert.assertEquals(HMacs.mac(text9).toString(),"w0Hajv1tjcN1xDX+QyLcx77GiCw=");
78         Assert.assertEquals(HMacs.mac(text10).toString(),"2agRqn7w1PHDt52VVs3z/EK1s8M=");
79      }
80
81     /**
82      * test file Hmac
83      *
84      * @throws Exception
85      */

86     public void testFileHmac() throws Exception JavaDoc {
87         Assert.assertEquals(HMacs.macFromFile(RunTest.TEMPFOLDER + "readable.txt").toString(), "88L5GNtKuj/RgJCi+E9Cxv1YLOM=");
88     }
89 }
90
Popular Tags