JavaScript react-native AES Encryption matching Java Decryption algorithm react native encryption library,react native encryption example,react native

The Full code of my Java Encryption/Decryption algorithm:

public class AESEncryptUtil {

    private static AESEncryptUtil instance = new AESEncryptUtil();
    private String password = "123456";
    private Key key;
    private Cipher cipher;

    public AESEncryptUtil(){
        try {
            KeyGenerator kgen = KeyGenerator.getInstance("AES");
            kgen.init(128, new SecureRandom(password.getBytes()));
            SecretKey secretKey = kgen.generateKey();
            byte[] enCodeFormat = secretKey.getEncoded();
            key = new SecretKeySpec(enCodeFormat, "AES");
            cipher = Cipher.getInstance("AES");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static byte[] encrypt(String content) throws Exception {
        byte[] byteContent = content.getBytes("utf-8");
        instance.cipher.init(Cipher.ENCRYPT_MODE, instance.key);
        byte[] result = instance.cipher.doFinal(byteContent);
        return result;
    }
    public static byte[] decrypt(byte[] content) throws Exception {
        instance.cipher.init(Cipher.DECRYPT_MODE, instance.key);
        byte[] result = instance.cipher.doFinal(content);
        return result;
    }
    public static String parseByte2HexStr(byte buf[]) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < buf.length; i++) {
            String hex = Integer.toHexString(buf[i] & 0xFF);
            if (hex.length() == 1) {
                hex = '0' + hex;
            }
            sb.append(hex.toUpperCase());
        }
        return sb.toString();
    }
    public static byte[] parseHexStr2Byte(String hexStr) {
        if (hexStr.length() < 1)
            return null;
        byte[] result = new byte[hexStr.length() / 2];
        for (int i = 0; i < hexStr.length() / 2; i++) {
            int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
            int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2),
                    16);
            result[i] = (byte) (high * 16 + low);
        }
        return result;
    }
    public static String getNonce() {
        String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 16; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }
    public static void main(String[] args) throws Exception {
        String content = "test";  
        System.out.println("content: " + content);  
        byte[] encryptResult = encrypt(content);  
        String encryptResultStr = parseByte2HexStr(encryptResult);  
        System.out.println("encryptResultStr: " + encryptResultStr);  
        byte[] decryptFrom = parseHexStr2Byte(encryptResultStr);  
        byte[] decryptResult = decrypt(decryptFrom);  
        System.out.println("decryptResult: " + new String(decryptResult));  
    }
} 

I've tried many times and many ways to match the Java algorithm, but the result are always different. Which module should I use to do this ? Can anyone help me to deal it ? Thanks a lot !

Answer:1

I want to join two objects with functions into a merged object using ES6, not sure how to do this. For example, I'd like to merge these two objects: const first = { first: function() { return {...

I want to join two objects with functions into a merged object using ES6, not sure how to do this. For example, I'd like to merge these two objects: const first = { first: function() { return {...

  1. merge objects with same key javascript
  2. merge objects with spread operator
  3. merge objects with arrays javascript
  4. merge objects with same key
  5. merge objects with same id
  6. merge objects with automapper
  7. merge objects with javascript
  8. merge objects with same property
  9. merge objects with array
  10. merge objects with
  11. merge objects with blender
  12. merge objects in illustrator
  13. merge objects by key javascript
  14. merge objects in powerpoint
  15. merge objects in 3ds max
  16. merge objects in word
  17. merge objects in inkscape
  18. merge objects in cinema 4d
  19. merge objects in array lodash
  20. merge objects in js

Why does this code produce an array of 20 elements which are all undefined: > Array(20).map(function() { return 3; }) [ , , , , , , , , , , , , , , , , , , , ] Whereas this code produces an ...

Why does this code produce an array of 20 elements which are all undefined: > Array(20).map(function() { return 3; }) [ , , , , , , , , , , , , , , , , , , , ] Whereas this code produces an ...

Question Background: I'm learning AngularJS. I have created a simple app that takes in 3 form inputs, and on submission of this form a paginated list should be rendered. I have a dependancy on UI-...

Question Background: I'm learning AngularJS. I have created a simple app that takes in 3 form inputs, and on submission of this form a paginated list should be rendered. I have a dependancy on UI-...

I made a table that has checkboxes that show and hide rows to make it easier to compare specific rows. I wanted to add indeterminate checkboxes so that multiple rows can be selected or not selected at ...

I made a table that has checkboxes that show and hide rows to make it easier to compare specific rows. I wanted to add indeterminate checkboxes so that multiple rows can be selected or not selected at ...