/*
* This file is subject to the licence found in LICENCE.TXT in the root directory of the project.
* Copyright Jayasoft 2005 - All rights reserved
*
* #SNAPSHOT#
*/
package fr.jayasoft.crypto;
import java.util.Properties;
import junit.framework.TestCase;
import fr.jayasoft.crypto.decoder.Decoder;
import fr.jayasoft.crypto.encoder.Encoder;
import fr.jayasoft.crypto.keys.KeyGenerator;
import fr.jayasoft.crypto.utils.DecoderUtils;
import fr.jayasoft.crypto.utils.EncoderUtils;
public class PropertiesTest extends TestCase {
Properties _p = null;
public PropertiesTest() {
super();
}
public PropertiesTest(String arg0) {
super(arg0);
}
protected void setUp() throws Exception {
super.setUp();
_p = new Properties();
for (int i = 0; i < 100; i++) {
_p.setProperty("p" + i, "val" + i);
}
}
private void encodeDecodeProperties(Encoder encoder, Decoder decoder) {
try {
byte[] encodedP = EncoderUtils.encode(_p, encoder);
Properties decodedP = DecoderUtils.decodeProperties(encodedP, decoder);
assertEquals(_p, decodedP);
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
}
public void testImplementations() {
doTestAlgo(CryptoFactory.NONE);
doTestAlgo(CryptoFactory.DES);
doTestAlgo(CryptoFactory.BLOWFISH);
doTestAlgo(CryptoFactory.RSA);
}
public void doTestAlgo(String algo) {
System.out.println("Testing: " + algo);
Crypto c = CryptoFactory.get(algo);
KeyGenerator kg = c.getKeyGenerator();
Encoder e = c.newEncoder(kg.getEncodingKey());
Decoder d = c.newDecoder(kg.getDecodingKey());
encodeDecodeProperties(e,d);
}
}