簡體   English   中英

加密的字符串長度

[英]Encrypted string length

您好,我在使用密碼字符串獲取用戶pdf時遇到問題。 它顯示以下錯誤:

javax.crypto.IllegalBlockSizeException:使用填充密碼解密時,輸入長度必須是8的倍數

代碼在那里:

public void getPDF(WebRequest request, ResourceResponse response, Model model,
                   @RequestParam("cif") String cif, 
                   @RequestParam("cuenta") String cuenta, 
                   @RequestParam("objectId") String encryptedObjectId) throws Exception{

    log.info("Inicio metodo getPDF");

    OutputStream os = response.getPortletOutputStream();


     try {

        CipherHelper cipher = new CipherHelper(CipherHelper.TRIPLE_DES_ALGORITHM, InterfazConstantes.ENCRYPTION_KEY, InterfazConstantes.ENCRYPTION_SHIFT);
        String objectId = cipher.decrypt(encryptedObjectId, true);

public String getEncryptedObjectID() {
    try {
        CipherHelper cipher = new CipherHelper(CipherHelper.TRIPLE_DES_ALGORITHM, InterfazConstantes.ENCRYPTION_KEY, InterfazConstantes.ENCRYPTION_SHIFT);
        encryptedObjectID = cipher.encrypt(objectID, true);
    } catch (Exception e) {
    }

    return encryptedObjectID;
}

**我確定cryptocurrid id的長度為40,但是不能解決問題。

錯誤的蹤跡是:

javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
    at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..) ~[sunjce_provider.jar:1.6]
    at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..) ~[sunjce_provider.jar:1.6]

有人能幫我嗎?

謝謝

該問題最有可能是由於將String用於二進制數據(加密的文本= byte[] )。 然后使用默認編碼。

String s = new String(bytes, StandardCharsets.ISO_8859_1);// Single byte encoding
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
new OutputStreamWriter(outputStream, StandardCharsets.ISO_8859_1)
new InputStreamReader(inputStream, StandardCharsets.ISO_8859_1)

暫無
暫無

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

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