簡體   English   中英

Glassfish和Tomcat中的decodeBase64的不同結果

[英]Different results for decodeBase64 in Glassfish and Tomcat

我有一個值,我用特殊字符編碼,然后使用base64再次編碼,我的開發環境是標准使用Netbeans glassfish服務器,但是站點托管在Tomcat服務器上,對於完全相同的解密代碼,我似乎會得到不同的結果/功能,它在netbeans中完美運行,但是在tomcat上失敗,由於字符不同,我的特殊字符解碼代碼失敗

String key = enc_key;

// Create key and cipher
Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");

// decrypt the text
cipher.init(Cipher.DECRYPT_MODE, aesKey);
strDecrypted = new String(cipher.doFinal(Base64.decodeBase64(encrypted.getBytes())));

有什么建議么 :-( ?

您正在使用String(byte[])構造函數,但未指定編碼。 不要那樣做

同樣,也不要在未指定編碼的情況下調用String.getBytes() 您在顯示給我們的代碼中做了兩次-我的猜測是您在加密數據時做到了。 始終指定要使用的編碼。

現在我們不知道您使用的是哪個Base64類,但是我個人將嘗試找到一個接受String進行解碼的方法來開始-Base64在邏輯上是一個byte[] <==> String轉換方案,因此在一個不錯的API,您需要使用String encode(byte[])byte[] decode(String) String encode(byte[]) byte[] decode(String)

暫無
暫無

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

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