Search in sources :

Example 6 with I2PAppContext

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();
}
Also used : I2PAppContext(net.i2p.I2PAppContext)

Example 7 with I2PAppContext

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);
}
Also used : Set(java.util.Set) I2PAppContext(net.i2p.I2PAppContext) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) Properties(java.util.Properties) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 8 with I2PAppContext

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));
}
Also used : I2PAppContext(net.i2p.I2PAppContext) SessionKey(net.i2p.data.SessionKey)

Example 9 with I2PAppContext

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));
}
Also used : I2PAppContext(net.i2p.I2PAppContext) SessionKey(net.i2p.data.SessionKey)

Example 10 with I2PAppContext

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));
    }
}
Also used : PrivateKey(net.i2p.data.PrivateKey) I2PAppContext(net.i2p.I2PAppContext) PublicKey(net.i2p.data.PublicKey)

Aggregations

I2PAppContext (net.i2p.I2PAppContext)55 SessionKey (net.i2p.data.SessionKey)13 File (java.io.File)11 IOException (java.io.IOException)11 Properties (java.util.Properties)9 Test (org.junit.Test)7 Getopt (gnu.getopt.Getopt)5 ArrayList (java.util.ArrayList)5 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 InputStream (java.io.InputStream)3 DataFormatException (net.i2p.data.DataFormatException)3 Log (net.i2p.util.Log)3 SecureFileOutputStream (net.i2p.util.SecureFileOutputStream)3 Encoding (i2p.susi.webmail.encoding.Encoding)2 OutputStream (java.io.OutputStream)2 GeneralSecurityException (java.security.GeneralSecurityException)2 HashSet (java.util.HashSet)2 I2PSession (net.i2p.client.I2PSession)2 NamingService (net.i2p.client.naming.NamingService)2