如何从CipherInputStream中提取数据?

时间:2014-10-08 20:09:13

标签: java android encryption

我解密内部存储器上的文件,如下所示:

CipherInputStream cip = new CipherInputStream(context.openFileInput("filename"), cipher);

如何获取解码结果并将其转换为字符串?


更新

存储在手机内存中的文件是加密的json文件。该方法应读取此文件,解密并将结果作为字符串返回:

public String getJSON() {
            String jsonString = "";

    try {
            String algorithm = "DESede";
            jsonString = "";
            SecretKeyFactory skf = SecretKeyFactory.getInstance(algorithm);
            DESedeKeySpec kspec = new DESedeKeySpec(readKey().getBytes());
            SecretKey key = skf.generateSecret(kspec);
            Cipher cipher = Cipher.getInstance(algorithm);
            cipher.init(Cipher.DECRYPT_MODE, key);
            CipherInputStream cip = new CipherInputStream(context.openFileInput("filename"), cipher);

            // here I have to get the result of decoding and write it to the jsonString

            cip.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonString;
    }

0 个答案:

没有答案