Search in sources :

Example 6 with OtrOutputStream

use of net.java.otr4j.io.OtrOutputStream in project Zom-Android by zom.

the class IOTest method testIOBigInt.

public void testIOBigInt() throws Exception {
    KeyPair pair = new OtrCryptoEngineImpl().generateDHKeyPair();
    BigInteger source = ((DHPublicKey) pair.getPublic()).getY();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OtrOutputStream oos = new OtrOutputStream(out);
    oos.writeBigInt(source);
    oos.close();
    byte[] converted = out.toByteArray();
    ByteArrayInputStream bin = new ByteArrayInputStream(converted);
    OtrInputStream ois = new OtrInputStream(bin);
    BigInteger result = ois.readBigInt();
    ois.close();
    assertTrue(source.compareTo(result) == 0);
}
Also used : KeyPair(java.security.KeyPair) DHPublicKey(javax.crypto.interfaces.DHPublicKey) ByteArrayInputStream(java.io.ByteArrayInputStream) OtrInputStream(net.java.otr4j.io.OtrInputStream) OtrCryptoEngineImpl(net.java.otr4j.crypto.OtrCryptoEngineImpl) BigInteger(java.math.BigInteger) OtrOutputStream(net.java.otr4j.io.OtrOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with OtrOutputStream

use of net.java.otr4j.io.OtrOutputStream in project Zom-Android by zom.

the class SM method serialize.

public static byte[] serialize(BigInteger[] ints) throws SMException {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        OtrOutputStream oos = new OtrOutputStream(out);
        oos.writeInt(ints.length);
        for (BigInteger i : ints) {
            oos.writeBigInt(i);
        }
        byte[] b = out.toByteArray();
        oos.close();
        return b;
    } catch (IOException ex) {
        throw new SMException("cannot serialize bigints");
    }
}
Also used : BigInteger(java.math.BigInteger) OtrOutputStream(net.java.otr4j.io.OtrOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 OtrOutputStream (net.java.otr4j.io.OtrOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 OtrInputStream (net.java.otr4j.io.OtrInputStream)4 IOException (java.io.IOException)3 DHPublicKey (javax.crypto.interfaces.DHPublicKey)3 OtrCryptoEngineImpl (net.java.otr4j.crypto.OtrCryptoEngineImpl)3 BigInteger (java.math.BigInteger)2 KeyPair (java.security.KeyPair)2 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 OtrException (net.java.otr4j.OtrException)1 OtrCryptoEngine (net.java.otr4j.crypto.OtrCryptoEngine)1 SMException (net.java.otr4j.crypto.SM.SMException)1 DataMessage (net.java.otr4j.io.messages.DataMessage)1 MysteriousT (net.java.otr4j.io.messages.MysteriousT)1