RSA中文加密亂碼問題

2021-10-09 10:44:49 字數 803 閱讀 1571

記錄一次,**中使用rsa加密,本地以及測試環境中文加密正常,不會出現亂碼,但是生產環境會出現中文亂碼。

排查一段時間,定位到問題;

針對中文獲取位元組流時,指定utf-8編碼--**如下

int inputlen = data.getbytes(utf_8).length;以此類推,所以獲取位元組流位置,均新增指定utf-8編碼

/**

* rsa加密

** @param data 待加密資料

* @param publickey 公鑰

* @return

*/public static string encrypt(string data, publickey publickey) throws exception {

cipher cipher = cipher.getinstance(encrypt_content);

cipher.init(cipher.encrypt_mode, publickey);

int inputlen = data.getbytes(utf_8).length;

bytearrayoutputstream out = new bytearrayoutputstream();

int offset = 0;

byte cache;

int i = 0;

// 對資料分段加密

while (inputlen - offset > 0) {

if (inputlen - offset > max_encrypt_block) {

php rsa加密亂碼 php 的rsa加密與解密

php 的rsa加密與解密 php 的rsa加密與解密 linux系統生成公私鑰對方法 openssl genrsa out rsa private key.pem 1024 openssl pkcs8 topk8 inform pem in rsa private key.pem outform ...

中文亂碼問題

母頁 tran cel.jsp?p user id p user id p paraxml mytran cel paraxml ie8對window.open二進位製流會遮蔽,用二次請求解決該問題 modify by 20120731。mytran cel paraxml encodeuri my...

中文亂碼問題

url位址中傳遞中文,接收亂碼。修改tomcat的server.xml.在埠號那一項中增加 uriencoding utf 8 connectiontimeout 20000 redirectport 8443 uriencoding utf 8 在form表單中中文亂碼 1.保證你的專案的屬性是u...