1 20 21 package net.sourceforge.lightcrypto.test; 22 23 import junit.framework.Assert; 24 import junit.framework.TestCase; 25 import net.sourceforge.lightcrypto.Digesters; 26 27 import java.io.DataOutputStream ; 28 import java.io.FileOutputStream ; 29 import java.io.IOException ; 30 31 41 42 public class DigestTest extends TestCase { 43 private StringBuffer text1; 44 private StringBuffer text2; 45 private StringBuffer text3; 46 private StringBuffer text4; 47 private StringBuffer text5; 48 private StringBuffer text6; 49 private StringBuffer text7; 50 private StringBuffer text8; 51 private StringBuffer text9; 52 private StringBuffer text10; 53 54 59 protected void setUp() throws IOException { 60 text1 = new StringBuffer ("The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms"); 61 text2 = new StringBuffer ("This software is distributed under a license based on the MIT X Consortium license"); 62 text3 = new StringBuffer ("found in $JAVA_HOME/jre/lib/security/java.security, where $JAVA_HOME is the location of your JDK/JRE distribution"); 63 text4 = new StringBuffer ("Mit Project 2002 zum erfolgreichen Projektmanagement Damit Sie in Zukunft Ihre Projekte präzise und komfortabel steuern können"); 64 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"); 65 text6 = new StringBuffer ("Lees de productinformatie en ontdek alles over de krachtige tools binnen Visual Studio .NET"); 66 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"); 67 text8 = new StringBuffer ("An implementation of ECIES (stream mode) as described in IEEE P 1363a."); 68 text9 = new StringBuffer ("This makes the entire keystore resistant to tampering and inspection, and forces verification"); 69 text10 = new StringBuffer ("application/pkcs7-signature;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_signature"); 70 71 FileOutputStream outStr = new FileOutputStream (RunTest.TEMPFOLDER + "readable.txt"); 73 DataOutputStream dataStr = new DataOutputStream (outStr); 74 75 dataStr.writeBytes("This is a readable string inside a file"); 76 77 dataStr.flush(); 78 dataStr.close(); 79 80 outStr.close(); 81 } 82 83 88 public void testDigest() throws Exception { 89 Assert.assertEquals(Digesters.digest(text1, null).toString(), "GPMnLEpblugEcs2kmFkg3Q=="); 90 Assert.assertEquals(Digesters.digest(text2, null).toString(), "LPcC8hTqwv/qBcDUQdpx4w=="); 91 Assert.assertEquals(Digesters.digest(text3, null).toString(), "1pWkqCss4OvVPCv0fcSBgQ=="); 92 Assert.assertEquals(Digesters.digest(text4, null).toString(), "6kqKaRJHN1an+j+u2fUvHA=="); 93 Assert.assertEquals(Digesters.digest(text5, null).toString(), "KJ+Ve5/s8HDv/xu49lsf3g=="); 94 Assert.assertEquals(Digesters.digest(text6, null).toString(), "a7syvGijznXELm/sOctixw=="); 95 Assert.assertEquals(Digesters.digest(text7, null).toString(), "Pw3X59NMqZEYaOyKDPXn1g=="); 96 Assert.assertEquals(Digesters.digest(text8, null).toString(), "uA+eNem45Shm+4SWImwFDw=="); 97 Assert.assertEquals(Digesters.digest(text9, null).toString(), "jMU70cRMB3LnWkWrWhczBg=="); 98 Assert.assertEquals(Digesters.digest(text10, null).toString(), "BytgzY4DVd4pFgyQLK1rMw=="); 99 100 Assert.assertEquals(Digesters.digest(text8, "SHA1").toString(), "U81M41/RyigieCM/7xnIfO9cDyY="); 102 } 103 104 109 public void testFileDigest() throws Exception { 110 Assert.assertEquals(Digesters.digestFromFile(RunTest.TEMPFOLDER + "readable.txt", null).toString(), "oHHF8dn23j348n/jrII7nA=="); 111 } 112 } 113 | Popular Tags |