Java DIDISOFT PGP Lib在特定字符串解密期间挂起

Java DIDISOFT PGP Lib在特定字符串解密期间挂起,java,encryption,pgp,Java,Encryption,Pgp,当我加密下面的字符串时,下面的字符串的长度显然大于1024,一旦加密它就可以解密,但是一旦字符串减少到小于1024,它就可以在不挂起的情况下解密字符串 String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<FTSingleCreditResponse&

当我加密下面的字符串时,下面的字符串的长度显然大于1024,一旦加密它就可以解密,但是一旦字符串减少到小于1024,它就可以在不挂起的情况下解密字符串

String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
                + "<FTSingleCreditResponse>\n"
                + "    <Amount>1000.00</Amount>\n"
                + "    <BeneficiaryAccountName>Akogun Olasoji</BeneficiaryAccountName>\n"
                + "    <BeneficiaryAccountNumber>000000020</BeneficiaryAccountNumber>\n"
                + "    <BeneficiaryBankVerificationNumber></BeneficiaryBankVerificationNumber>\n"
                + "    <BeneficiaryKYCLevel>1</BeneficiaryKYCLevel>\n"
                + "    <ChannelCode>12</ChannelCode>\n"
                + "    <DestinationInstitutionCode>999194</DestinationInstitutionCode>\n"
                + "    <NameEnquiryRef>999999200825144654200825144654</NameEnquiryRef>\n"
                + "    <Narration>Transaction from me you</Narration>\n"
                + "    <OriginatorAccountName>Ajao Niyi</OriginatorAccountName>\n"
                + "    <OriginatorAccountNumber>0105498919</OriginatorAccountNumber>\n"
                + "    <OriginatorBankVerificationNumber>10000000002</OriginatorBankVerificationNumber>\n"
                + "    <OriginatorKYCLevel>1</OriginatorKYCLevel>\n"
                + "    <PaymentReference>ref/2015/08/05/val 3</PaymentReference>\n"
                + "    <ResponseCode>00</ResponseCode>\n"
                + "    <SessionID>999999200827170808200827170807</SessionID>\n"
                + "    <TransactionLocation>6.4300747,3.4110715</TransactionLocation>\n"
                + "</FTSingleCreditResponse>";
解密

public String encrypt(String text) {
        try {
            PGPLib pgp = new PGPLib();
            boolean armor = false;
            boolean withIntegrityCheck = true;

            ByteArrayOutputStream o = new ByteArrayOutputStream();
            logger.debug("step 1");
            InputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
            logger.debug("step 2");
            if (publicKeyFile == null) {
                publicKeyFile = new File(publicKeyLocation);
            }
            logger.debug("step 3");
            InputStream publicKeyStream = new FileInputStream(publicKeyFile);
            logger.debug("step 4");
            pgp.encryptStream(is, publicKeyLocation, publicKeyStream, o, armor,
                    withIntegrityCheck);
            logger.debug("step 5");
            byte[] body = o.toByteArray();
            int numberRead = body.length;
            logger.debug(" -|- SSModuleClient :: pickMessage :: numberRead: " + numberRead);
            return byte2hex(body);
        } catch (IOException ex) {
            logger.debug(" -|- SSModule :: MessageProcessor :: encrypt () :: Error Occurred ..."
                    + ex.getMessage());
            logger.debug("SSModule", ex);
        } catch (PGPException ex) {
            logger.debug(" -|- SSModule :: MessageProcessor :: encrypt () :: Error Occurred ..."
                    + ex.getMessage());
            logger.debug("SSModule", ex);
        }

        return "";
    }
public String decrypt(String text) {

        String decryptedMessage = "";

        try {
            byte[] bytText = hex2byte(text);

            PGPLib pgp = new PGPLib();

            InputStream iStream = new ByteArrayInputStream(bytText);

            logger.debug("SSModule :: decrypt () :: iStream.available(): "
                    + iStream.available());

            if (privateKeyFile == null) {
                privateKeyFile = new File(privateKeyLocation);
            }
            InputStream privateKeyStream = new FileInputStream(privateKeyLocation);
            PipedInputStream pin = new PipedInputStream();
            OutputStream oStream = new PipedOutputStream(pin);

            logger.debug("text: " + text);

            logger.info("privateKeyPassPhrase: " + privateKeyPassPhrase);

            pgp.decryptStream(iStream, privateKeyStream, getPrivateKeyPassPhrase(),
                    oStream);
            do {
                logger.debug("pin.available(): " + pin.available());
            } while (pin.available() <= 0);
            byte[] body = new byte[pin.available()];
            pin.read(body);
            decryptedMessage = new String(body).toString();
        } catch (Exception ex) {
            logger.debug("SSModule :: MessageProcessor :: decrypt () :: Error Occurred ..."
                    + ex.getMessage());
            logger.debug("SSModule", ex);
        }

        return decryptedMessage;
    }
公共字符串解密(字符串文本){
字符串decryptedMessage=“”;
试一试{
byte[]bytText=hex2byte(文本);
PGPLib pgp=新的PGPLib();
InputStream IsStream=新的ByteArrayInputStream(bytText);
logger.debug(“SSModule::decrypt()::iStream.available():”
+iStream.available());
if(privateKeyFile==null){
privateKeyFile=新文件(privateKeyLocation);
}
InputStream privateKeyStream=新文件InputStream(privateKeyLocation);
PipedInputStream引脚=新的PipedInputStream();
OutputStream oStream=新管道输出流(pin);
logger.debug(“文本:“+text”);
logger.info(“privateKeyPassPhrase:+privateKeyPassPhrase”);
pgp.decryptStream(iStream、privateKeyStream、getPrivateKeyPassPhrase(),
奥斯特雷姆);
做{
debug(“pin.available():”+pin.available());

}while(pin.available()嗨,Alex,有什么异常吗?或者只是有点奇怪。你为什么不使用PGPLib.encryptString和.decryptString方法而不是Stream方法呢?@AtanasKrachev它只是冻结了,没有异常。我更新了库并使用了“encryptString”Alex,如果你还有任何问题,你可以联系Di直接拒绝