您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将硬编码文件解密为字节[]

将硬编码文件解密为字节[]

共享密钥和加密某些东西是完全不同的两件事。如何分享金钥

话虽如此,AES使用128位元比使用128位元的加密算法要强大得多。3DES因此,您可以做的是保持PKI基础结构交换AES keys,然后使用它们进行加密和解密。

为什么不RSA呢?RSA需要最少512位才能将其视为最强,如果增加更多位,则将增加加密和解密所需的时间。

SO AES快速安全。

使用SecretKeySpec从字节创建密钥[]

public static void main(String[] args) throws Exception
{
    // Initialise secret key with predefined byte array [] like below. I
    // have used simple string to array method to generate 16 byte array.
    // AES Key must be minimum 16 bytes.
    // Now you can put this byte array some where is .so file.
    // Generate new Key using this byte []
    // Then you can generate a key using device specific information at
    // first boot up.
    // Use second key to encrypt data and first key to encrypt the second
    // key
    // I Hope it clears all the doubts
    SecretKey key = new SecretKeySpec("ABCDEFGHIJKLMNOP".getBytes(), "AES");
    System.out.println(Arrays.toString(key.getEncoded()));
    // Initialise Cipher with AES Algorithm
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    // Set The Encrypt Mode
    cipher.init(Cipher.ENCRYPT_MODE, key);
    // Encrypt some bytes
    byte[] encrypted = cipher.doFinal("ABCDEFGH".getBytes());
    // Print it to vefiry
    System.out.println(Arrays.toString(encrypted));

    // Get The IV
    byte[] iv = cipher.getIV();
    System.out.println(iv.length);
    // Now why storing you can create structure like [16 IV][Encrypted Data]
    // And while decrypting you can read first [16] bytes IV and then
    // decrypt remaining bytes

    //byte[] iv = new byte[16];
    // System.arraycopy(encrypted, 0, iv, 0, 16)
    //Copy remaining bytes to decrypt


    // set cipher to decrypt mode

    cipher.init(Cipher.DECRYPT_MODE, key,new IvParameterSpec(iv));

    // decrypt it
    byte[] decrypted = cipher.doFinal(encrypted);
    System.out.println(new String(decrypted));

}

现在编写一种算法,该算法将从某些随机数据(例如设备名称用户名随机种子等)生成byte []。

您可以通过在算法源代码中编写该算法C并创建.so文件并byte []使用来为其添加更多保护Native calls。

完成所有这些操作有什么好处?

其他 2022/1/1 18:16:17 有515人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶