简体   繁体   中英

Decrypt a file in php which is encrypted in android

I encrypted a file in android using triple des. This file is uploaded to the server using php. Have to write php script to decrypt the same file.

New to php, any help would be appreciated with php scripts.

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();
}

I'm passing hard coded values for keyBytes and iv which are hexadecimal values.

So, it seems like you are going to have to use the mcrypt extension. The mcrypt extension supports TRIPLEDES.

Installation

List of ciphers supported by mcrypt.

Here are some mcrypt examples .

The mcrypt function to decrypt is here .

I'm currently learning android and advanced php. If you are new to php, I highly recommend going to php.net for everything. It's been very helpful for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM