use of net.i2p.I2PAppContext in project i2p.i2p by i2p.
the class TestSwarm method main.
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Usage: TestSwarm myDestFile [peerDestFile ]*");
return;
}
I2PAppContext ctx = new I2PAppContext();
String[] files = new String[args.length - 1];
System.arraycopy(args, 1, files, 0, files.length);
TestSwarm swarm = new TestSwarm(ctx, args[0], files);
swarm.startup();
}
use of net.i2p.I2PAppContext in project i2p.i2p by i2p.
the class BlockfileNamingServiceTest method setUp.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setUp() throws Exception {
I2PAppContext ctx = new I2PAppContext();
routerDir = ctx.getRouterDir();
// first load the list of hosts that will be queried
InputStream is = getClass().getResourceAsStream("/hosts.txt");
Properties props = new Properties();
assertNotNull("test classpath not set correctly", is);
DataHelper.loadProps(props, is, true);
// TODO-Java6: s/keySet()/stringPropertyNames()/
_names = new ArrayList<String>((Set<String>) (Set) props.keySet());
Collections.shuffle(_names);
is.close();
// then copy the hosts.txt file so that the naming service can load them
hostsTxt = new File(routerDir, "hosts.txt");
OutputStream os = new BufferedOutputStream(new FileOutputStream(hostsTxt));
is = getClass().getResourceAsStream("/hosts.txt");
byte[] b = new byte[8196];
int read = 0;
while ((read = is.read(b)) > 0) os.write(b, 0, read);
os.flush();
os.close();
_bns = new BlockfileNamingService(ctx);
}
use of net.i2p.I2PAppContext in project i2p.i2p by i2p.
the class AES256Test method testShort.
public void testShort() {
I2PAppContext ctx = new I2PAppContext();
SessionKey key = ctx.keyGenerator().generateSessionKey();
byte[] iv = new byte[16];
RandomSource.getInstance().nextBytes(iv);
byte[] sbuf = new byte[16];
RandomSource.getInstance().nextBytes(sbuf);
byte[] se = new byte[16];
ctx.aes().encrypt(sbuf, 0, se, 0, key, iv, sbuf.length);
byte[] sd = new byte[16];
ctx.aes().decrypt(se, 0, sd, 0, key, iv, se.length);
assertTrue(DataHelper.eq(sd, sbuf));
}
use of net.i2p.I2PAppContext in project i2p.i2p by i2p.
the class CryptixAESEngineTest method testED.
public void testED() {
I2PAppContext ctx = I2PAppContext.getGlobalContext();
SessionKey key = ctx.keyGenerator().generateSessionKey();
byte[] iv = new byte[16];
byte[] orig = new byte[128];
byte[] encrypted = new byte[128];
byte[] decrypted = new byte[128];
ctx.random().nextBytes(iv);
ctx.random().nextBytes(orig);
CryptixAESEngine aes = new CryptixAESEngine(ctx);
aes.encrypt(orig, 0, encrypted, 0, key, iv, orig.length);
aes.decrypt(encrypted, 0, decrypted, 0, key, iv, encrypted.length);
assertTrue(DataHelper.eq(decrypted, orig));
}
use of net.i2p.I2PAppContext in project i2p.i2p by i2p.
the class ElGamalTest method testElGamalEngine.
public void testElGamalEngine() {
int numRuns = 10;
RandomSource.getInstance().nextBoolean();
I2PAppContext context = I2PAppContext.getGlobalContext();
for (int i = 0; i < numRuns; i++) {
Object[] pair = KeyGenerator.getInstance().generatePKIKeypair();
PublicKey pubkey = (PublicKey) pair[0];
PrivateKey privkey = (PrivateKey) pair[1];
byte[] buf = new byte[128];
RandomSource.getInstance().nextBytes(buf);
byte[] encr = context.elGamalEngine().encrypt(buf, pubkey);
byte[] decr = context.elGamalEngine().decrypt(encr, privkey);
assertTrue(DataHelper.eq(decr, buf));
}
}
Aggregations