Package tahrir.io.crypto

Source Code of tahrir.io.crypto.TrSymKeyTest

package tahrir.io.crypto;

import java.util.Random;

import org.testng.Assert;
import org.testng.annotations.Test;

import tahrir.tools.ByteArraySegment;

public class TrSymKeyTest {
  @Test
  public void testEncryptDecrypt() {
    final TrSymKey key = TrCrypto.createAesKey();
    final Random r = new Random();
    final byte[] plainText_ = new byte[512];
    r.nextBytes(plainText_);
    System.out.format("PlainText size: %s bytes%n", plainText_.length);
    final ByteArraySegment plainText = new ByteArraySegment(plainText_);
    final ByteArraySegment cypherText = key.encrypt(plainText);
    System.out.format("CypherText size: %s bytes%n", cypherText.length);
    final ByteArraySegment decryptedCypherText = key.decrypt(cypherText);
    Assert.assertEquals(decryptedCypherText, plainText);
  }

  @Test
  public void testSymKeySize(){
    final TrSymKey key = TrCrypto.createAesKey();
    Assert.assertEquals(key.toBytes().length, 16);

  }
}
TOP

Related Classes of tahrir.io.crypto.TrSymKeyTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.