簡體   English   中英

用php解密在android中加密的文件

[英]Decrypt a file in php which is encrypted in android

我使用三重des在android中加密了文件。 此文件使用php上傳到服務器。 必須編寫php腳本來解密相同的文件。

php新手,任何幫助將不勝感激php腳本。

public void encrypt(InputStream in, OutputStream out) throws Exception {
    final SecretKey key = new SecretKeySpec(keyBytes, "DESede");
    final IvParameterSpec param = new IvParameterSpec(iv);
    final Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE, key, param);

    // Read in the cleartext bytes and write to out to encrypt
    int numRead = 0;
    while ((numRead = in.read(buf)) >= 0) {
        byte[] output = cipher.doFinal(buf, 0, numRead);
        if(output != null) {
            byte[] enc = Base64.encode(output, 0);
            out.write(enc);
        }   
    }
    out.close();
}

我正在傳遞keyBytesiv硬編碼值,它們是十六進制值。

因此,似乎您將不得不使用mcrypt擴展。 mcrypt擴展支持TRIPLEDES。

安裝

mcrypt支持的密碼列表

這是一些mcrypt 示例

解密的mcrypt函數在這里

我目前正在學習android和高級php。 如果您不熟悉php,我強烈建議您訪問php.net。 這對我很有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM