共享密钥和加密某些东西是完全不同的两件事。如何分享金钥
话虽如此,
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个设备
- 黑客将不得不对每台设备重复相同的操作,这几乎是不可能的。


![将硬编码文件解密为字节[] 将硬编码文件解密为字节[]](http://www.mshxw.com/aiimages/31/438264.png)
