Exemplo n.º 1
0
 public byte[] xtsBlockEncrypt(byte[] plain, int j) {
   byte[] pp = xor(plain, tTable[j]);
   aes.setKey(key1);
   byte[] cc = aes.encrypt(pp);
   byte[] cj = xor(cc, tTable[j]);
   return cj;
 }
 public static String encrypt(
     final String text, final String password, final byte[] salt, final byte[] iv) {
   final byte[] data = CryptoHelper.getRawBytes(text);
   final byte[] encryptedData =
       AES.encrypt(data, password, salt, iv, AES.KEY_SIZE_DEFAULT, AES.ITERATION_COUNT_DEFAULT);
   return CryptoHelper.base64Encode(encryptedData);
 }
 public static byte[] encrypt(
     final byte[] data,
     final String password,
     final byte[] salt,
     final byte[] iv,
     final int keySize) {
   return AES.encrypt(data, password, salt, iv, keySize, AES.ITERATION_COUNT_DEFAULT);
 }
 public static byte[] encrypt(final byte[] data, final String password, final byte[] salt) {
   return AES.encrypt(
       data,
       password,
       salt,
       AES.getSimpleIV(),
       AES.KEY_SIZE_DEFAULT,
       AES.ITERATION_COUNT_DEFAULT);
 }
 public static byte[] encrypt(final byte[] data) {
   return AES.encrypt(
       data,
       AES.getSimplePassword(),
       AES.getSimpleSalt(),
       AES.getSimpleIV(),
       AES.KEY_SIZE_DEFAULT,
       AES.ITERATION_COUNT_DEFAULT);
 }
Exemplo n.º 6
0
 public void start() {
   try {
     System.out.println(0x100);
     // key
     FileReader fr = new FileReader(k);
     BufferedReader buff = new BufferedReader(fr);
     String temp = buff.readLine();
     key1 = temp.substring(0, 16).getBytes();
     key2 = temp.substring(16, 32).getBytes();
     aes.setKey(key2);
     String input = "";
     // input
     fr = new FileReader(i);
     buff = new BufferedReader(fr);
     temp = buff.readLine();
     if (temp != null) {
       input = temp;
     }
     while ((temp = buff.readLine()) != null) {
       input = input + "\r" + temp;
     }
     System.out.println(input);
     plain = input.getBytes();
     plainBlock = new byte[(int) Math.ceil(plain.length / 16)][16];
     for (int i = 0; i < plainBlock.length; i++) {
       System.arraycopy(plain, 16 * i, plainBlock[i], 0, 16);
     }
     for (int i = 0; i < plain.length; i++) {
       System.out.print(plain[i] + " ");
     }
     System.out.println();
     for (int i = 0; i < plainBlock.length; i++) {
       for (int j = 0; j < plainBlock[i].length; j++) {
         System.out.print(plainBlock[i][j] + " ");
       }
       System.out.println();
     }
     tTable = new byte[plainBlock.length][16];
     tweakAfterEncrypt = aes.encrypt(tweak);
     fillTTable();
     // output
     FileWriter fw = new FileWriter(o);
     BufferedWriter bw = new BufferedWriter(fw);
     for (int i = 0; i < plainBlock.length - 2; i++) {
       xtsBlockEncrypt(plain, i);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 7
0
  @Test
  public void test()
      throws NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException,
          IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException,
          UnsupportedEncodingException, InvalidAlgorithmParameterException {
    String data1 = "阿迪是发送发达撒地方";
    String key = "ABCDABCDABCDABCD12";

    System.out.println("原数据为:" + data1);
    System.out.println("密匙为:" + key);

    String data2 = AES.encrypt(key, data1, AES.ALGORITHM_ECB);
    System.out.println("加密后数据为:" + data2);

    String data3 = AES.decrypt(key, data2, AES.ALGORITHM_ECB);
    System.out.println("解密后数据为:" + data3);
    Assert.assertEquals(data1, data3);
  }
 public static String encrypt(final String text, final String password, final byte[] salt) {
   return AES.encrypt(text, password, salt, AES.getSimpleIV());
 }
 public static String encrypt(final String text, final String password) {
   return AES.encrypt(text, password, AES.getSimpleSalt(), AES.getSimpleIV());
 }