栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

话虽如此,

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.getEnpred()));    // 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。

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

  1. 如果您的黑客被黑客入侵,则需要实时环境来运行创建密钥。
  2. 即使有人破解了它,损坏也将是有限的,即1个设备
  3. 黑客将不得不对每台设备重复相同的操作,这几乎是不可能的。


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/438264.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号