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 ; 8 import java.io.FileOutputStream ; 9 import java.io.IOException ; 10 11 21 22 public class HMacTest extends TestCase { 23 private StringBuffer text1; 24 private StringBuffer text2; 25 private StringBuffer text3; 26 private StringBuffer text4; 27 private StringBuffer text5; 28 private StringBuffer text6; 29 private StringBuffer text7; 30 private StringBuffer text8; 31 private StringBuffer text9; 32 private StringBuffer text10; 33 34 39 protected void setUp() throws IOException { 40 text1= new StringBuffer ("The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms"); 41 text2= new StringBuffer ("This software is distributed under a license based on the MIT X Consortium license"); 42 text3= new StringBuffer ("found in $JAVA_HOME/jre/lib/security/java.security, where $JAVA_HOME is the location of your JDK/JRE distribution"); 43 text4= new StringBuffer ("Mit Project 2002 zum erfolgreichen Projektmanagement Damit Sie in Zukunft Ihre Projekte präzise und komfortabel steuern können"); 44 text5= new StringBuffer ("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 ("Lees de productinformatie en ontdek alles over de krachtige tools binnen Visual Studio .NET"); 46 text7= new StringBuffer ("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 ("An implementation of ECIES (stream mode) as described in IEEE P 1363a."); 48 text9= new StringBuffer ("This makes the entire keystore resistant to tampering and inspection, and forces verification"); 49 text10= new StringBuffer ("application/pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_signature"); 50 51 FileOutputStream outStr = new FileOutputStream (RunTest.TEMPFOLDER + "readable.txt"); 53 DataOutputStream dataStr = new DataOutputStream (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 68 public void testHmac() throws Exception { 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 86 public void testFileHmac() throws Exception { 87 Assert.assertEquals(HMacs.macFromFile(RunTest.TEMPFOLDER + "readable.txt").toString(), "88L5GNtKuj/RgJCi+E9Cxv1YLOM="); 88 } 89 } 90 | Popular Tags |