Search in sources :

Example 46 with I2PAppContext

use of net.i2p.I2PAppContext in project i2p.i2p by i2p.

the class CryptixAESEngineTest method testEDBlock.

public static void testEDBlock() {
    I2PAppContext ctx = I2PAppContext.getGlobalContext();
    SessionKey key = ctx.keyGenerator().generateSessionKey();
    byte[] iv = new byte[16];
    byte[] orig = new byte[16];
    byte[] encrypted = new byte[16];
    byte[] decrypted = new byte[16];
    ctx.random().nextBytes(iv);
    ctx.random().nextBytes(orig);
    CryptixAESEngine aes = new CryptixAESEngine(ctx);
    aes.encryptBlock(orig, 0, key, encrypted, 0);
    aes.decryptBlock(encrypted, 0, key, decrypted, 0);
    assertTrue(DataHelper.eq(decrypted, orig));
}
Also used : I2PAppContext(net.i2p.I2PAppContext) SessionKey(net.i2p.data.SessionKey)

Example 47 with I2PAppContext

use of net.i2p.I2PAppContext in project i2p.i2p by i2p.

the class CryptixAESEngineTest method testED2.

public static void testED2() {
    I2PAppContext ctx = I2PAppContext.getGlobalContext();
    SessionKey key = ctx.keyGenerator().generateSessionKey();
    byte[] iv = new byte[16];
    byte[] orig = new byte[128];
    byte[] data = new byte[128];
    ctx.random().nextBytes(iv);
    ctx.random().nextBytes(orig);
    CryptixAESEngine aes = new CryptixAESEngine(ctx);
    aes.encrypt(orig, 0, data, 0, key, iv, data.length);
    aes.decrypt(data, 0, data, 0, key, iv, data.length);
    assertTrue(DataHelper.eq(data, orig));
}
Also used : I2PAppContext(net.i2p.I2PAppContext) SessionKey(net.i2p.data.SessionKey)

Example 48 with I2PAppContext

use of net.i2p.I2PAppContext in project i2p.i2p by i2p.

the class CryptixAESEngineTest method testFake.

public static void testFake() {
    I2PAppContext ctx = I2PAppContext.getGlobalContext();
    SessionKey key = ctx.keyGenerator().generateSessionKey();
    SessionKey wrongKey = 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, wrongKey, iv, encrypted.length);
    assertFalse(DataHelper.eq(decrypted, orig));
}
Also used : I2PAppContext(net.i2p.I2PAppContext) SessionKey(net.i2p.data.SessionKey)

Example 49 with I2PAppContext

use of net.i2p.I2PAppContext in project i2p.i2p by i2p.

the class CryptixAESEngineTest method testEDBlock2.

public static void testEDBlock2() {
    I2PAppContext ctx = I2PAppContext.getGlobalContext();
    SessionKey key = ctx.keyGenerator().generateSessionKey();
    byte[] iv = new byte[16];
    byte[] orig = new byte[16];
    byte[] data = new byte[16];
    ctx.random().nextBytes(iv);
    ctx.random().nextBytes(orig);
    CryptixAESEngine aes = new CryptixAESEngine(ctx);
    aes.encryptBlock(orig, 0, key, data, 0);
    aes.decryptBlock(data, 0, key, data, 0);
    assertTrue(DataHelper.eq(data, orig));
}
Also used : I2PAppContext(net.i2p.I2PAppContext) SessionKey(net.i2p.data.SessionKey)

Example 50 with I2PAppContext

use of net.i2p.I2PAppContext in project i2p.i2p by i2p.

the class CryptixAESEngineTest method testNull.

public static void testNull() {
    I2PAppContext ctx = I2PAppContext.getGlobalContext();
    SessionKey key = ctx.keyGenerator().generateSessionKey();
    SessionKey wrongKey = 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);
    boolean error = false;
    try {
        aes.decrypt(null, 0, null, 0, wrongKey, iv, encrypted.length);
    } catch (IllegalArgumentException iae) {
        error = true;
    }
    assertTrue(error);
}
Also used : I2PAppContext(net.i2p.I2PAppContext) SessionKey(net.i2p.data.SessionKey)

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