CipherInputStream .available() returns 解密阶段为零

CipherInputStream .available() returns ZERO in decryption phase

我正在尝试使用为 ECIES 提供的示例在我的 android 应用程序中使用加密工具 flexiprovider。当我 运行 本地机器中的代码 Enc/Dec 工作时没有任何问题。但是当我尝试 运行 它作为 android 应用程序使用 android 工作室时,解密不起作用。

主要Activity.java

 public void onClick12 (View view) {
        ExampleECIES exampleECIES=new ExampleECIES();
        try {
            exampleECIES.main(null);
        } catch (Exception e) {
            Log.e("main()",e.getMessage());

        }
    }

加密方案:

package com.example.enctest3;
import android.Manifest;
import android.support.v4.app.ActivityCompat;
import android.util.Log;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;

import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;

import de.flexiprovider.common.exceptions.ECException;
import de.flexiprovider.common.ies.IESParameterSpec;
import de.flexiprovider.core.FlexiCoreProvider;
import de.flexiprovider.ec.FlexiECProvider;
import de.flexiprovider.ec.parameters.CurveParams;
import de.flexiprovider.ec.parameters.CurveRegistry.BrainpoolP160r1;

public class ExampleECIES {

public static void main(String[] args) throws Exception {

    Security.addProvider(new FlexiCoreProvider());
    Security.addProvider(new FlexiECProvider());

    KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECIES", "FlexiEC");

    CurveParams ecParams = new BrainpoolP160r1();

    kpg.initialize(ecParams, new SecureRandom());
    KeyPair keyPair = kpg.generateKeyPair();
    PublicKey pubKey = keyPair.getPublic();
    PrivateKey privKey = keyPair.getPrivate();

    // Encrypt

    Cipher cipher = Cipher.getInstance("ECIES", "FlexiEC");

    IESParameterSpec iesParams = new IESParameterSpec("AES128_CBC",
            "HmacSHA1", null, null);

    cipher.init(Cipher.ENCRYPT_MODE, pubKey, iesParams);
    String cleartextFile =     "/storage/emulated/0/Android/data/enctest3/files/cleartext.txt";
    String ciphertextFile = "/storage/emulated/0/Android/data/enctest3/files/ciphertextECIES.txt";
    byte[] block = new byte[64];
    FileInputStream fis = new FileInputStream(cleartextFile);
    FileOutputStream fos = new FileOutputStream(ciphertextFile);
    CipherOutputStream cos = new CipherOutputStream(fos, cipher);
    int i;
    while ((i = fis.read(block)) != -1) {
        cos.write(block, 0, i);
    }
    cos.close();
    fos.close();
    fis.close();
    // Decrypt

    String cleartextAgainFile = "/storage/emulated/0/Android/data/enctest3/files/cleartextAgainECIES.txt";

    cipher.init(Cipher.DECRYPT_MODE, privKey, iesParams);
    fis = new FileInputStream(ciphertextFile);

    CipherInputStream cis = new CipherInputStream(fis, cipher);
    fos = new FileOutputStream(cleartextAgainFile);
    int x=cis.available();
    Log.e("available()",Integer.toString(x));
    while ((i= cis.read(block)) != -1) {
        fos.write(block, 0, i);
    }

    fos.close();
}

}

这是日志:

 E/available(): 0
 E/main(): src.length=17 srcPos=0 dst.length=0 dstPos=0 length=17

与我的问题类似的posthere没有帮助。

我在另一台有虚拟设备的机器上试过运行这个应用程序,它没有任何问题。