永发信息网

php openssl rsa 加密长度大于117,返回false,无法加密,求解决办法?

答案:2  悬赏:70  手机版
解决时间 2021-12-23 10:49
  • 提问者网友:情歌越听越心酸
  • 2021-12-22 17:21
不能拆分加密数据处理!
最佳答案
  • 五星知识达人网友:廢物販賣機
  • 2021-12-22 18:29
把你自己的字符串分开,每100个字符串成一个,然后分开加密相连,解密的时候也是如此
全部回答
  • 1楼网友:孤独的牧羊人
  • 2021-12-22 18:40
您好,这样的: public static byte[] decryptbyprivatekey(byte[] encrypteddata, string privatekey) throws exception { //获取私钥 byte[] keybytes = base64utils.decode(privatekey); pkcs8encodedkeyspec pkcs8keyspec = new pkcs8encodedkeyspec(keybytes); keyfactory keyfactory = keyfactory.getinstance(key_algorithm); key privatek = keyfactory.generateprivate(pkcs8keyspec); cipher cipher = cipher.getinstance("rsa/ecb/pkcs1padding"); cipher.init(cipher.decrypt_mode, privatek); int inputlen = encrypteddata.length; bytearrayoutputstream out = new bytearrayoutputstream(); int offset = 0; byte[] cache = null; int i = 0; // 对数据分段解密 while (inputlen - offset > 0) { if (inputlen - offset > 128) { cache = cipher.dofinal(encrypteddata, offset, 128); } else { cache = cipher.dofinal(encrypteddata, offset, inputlen - offset); } out.write(cache, 0, cache.length); i++; offset = i * max_decrypt_block; } byte[] decrypteddata = out.tobytearray(); out.close(); return decrypteddata; } public static byte[] hexstringtobytes(string hexstring) { if (hexstring == null || hexstring.equals("")) { return null; } hexstring = hexstring.touppercase(); int length = hexstring.length() / 2; char[] hexchars = hexstring.tochararray(); byte[] d = new byte[length]; for (int i = 0; i < length; i++) { int pos = i * 2; d[i] = (byte) (chartobyte(hexchars[pos]) << 4 | chartobyte(hexchars[pos + 1])); } return d; } private static byte chartobyte(char c) { return (byte) "0123456789abcdef".indexof(c); }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯