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.Asymmetric; 27 import net.sourceforge.jcetaglib.lib.X509Cert; 28 29 import java.security.PrivateKey ; 30 import java.security.cert.X509Certificate ; 31 32 42 public class AsymmetricTest extends TestCase { 43 private StringBuffer ciphertext = null; 44 private StringBuffer plaintext = null; 45 46 51 public void testAsymmetric() throws Exception { 52 X509Certificate alicecert = X509Cert.getCertificateFromP12(RunTest.TEMPFOLDER + "alice.p12", "alice", new StringBuffer ("password")); 54 55 PrivateKey aliceprivate = X509Cert.getPrivateFromP12(RunTest.TEMPFOLDER + "alice.p12", "alice", new StringBuffer ("password")); 57 58 ciphertext = Asymmetric.encrypt(new StringBuffer ("Make sure this text is not too long or errors will be generated"), alicecert.getPublicKey()); 59 plaintext = Asymmetric.decrypt(ciphertext, aliceprivate); 60 61 Assert.assertEquals(plaintext.toString(), "Make sure this text is not too long or errors will be generated"); 62 } 63 } 64 | Popular Tags |