2

当设备连接到 USB 存储模式/设备上的内部文件浏览应用程序时,我想知道是否有人可以告诉我一种使 SD 卡上的文件夹隐藏/不可见/加密的方法。
我还需要能够从我的 android 应用程序访问这些文件(如果有任何不同,只能读取它们..)

我知道一些像 SecretVault pro 这样的文件加密应用程序,但是像这样的应用程序没有用于开发人员的 API,它允许逐步控制加密/破旧状态。

4

1 回答 1

15
 public byte[] keyGen() throws NoSuchAlgorithmException {
    KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
    keyGenerator.init(192);
    return keyGenerator.generateKey().getEncoded();
 }

你需要在你的应用程序中存储密钥

     public byte[] encript(byte[] dataToEncrypt, byte[] key)
            throws NoSuchAlgorithmException, NoSuchPaddingException,
            InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
    //I'm using AES encription
    Cipher c = Cipher.getInstance("AES");
    SecretKeySpec k = new SecretKeySpec(key, "AES");
    c.init(Cipher.ENCRYPT_MODE, k);
    return c.doFinal(dataToEncrypt);
    }

    public byte[] decript(byte[] encryptedData, byte[] key)
            throws NoSuchAlgorithmException, NoSuchPaddingException,
            InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
    Cipher c = Cipher.getInstance("AES");
    SecretKeySpec k = new SecretKeySpec(key, "AES");
    c.init(Cipher.DECRYPT_MODE, k);
    return c.doFinal(encryptedData);
    }
于 2012-04-23T06:41:53.390 回答