本文介绍了JAVA:PBEKeySpec带有字节数组参数,而不是ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种使用 PBEKeySpec 和字节数组参数的方法。

I would like to know if there is a way to use PBEKeySpec with a byte array argument.

请找到以下文档的链接:

Please find a link to the documentation below:

推荐答案

由于Java PKCS#5 KeyFactory 已指定为只使用低8位的 PBEKeySpec 中的字符,您应该能够将字节数组转换为(16位)字符数组,而不会出现问题。

As the Java PKCS#5 KeyFactory has been specified to only use the lower 8 bits of the characters in the PBEKeySpec, you should be able to convert your byte array into a (16 bit) character array without issue. Just copy the value of each byte into the character array and you should be set.

只要确定,我会执行 charArray [i] = byteArray [i]& 0xFF 作为赋值语句,否则你将得到非常高的字符。

Just to be sure, I would perform charArray[i] = byteArray[i] & 0xFF as assignment statement, otherwise you would get very high valued characters.

这是一个丑陋的解决方法,但我没有看到任何理由它不应该工作。

It's an ugly workaround, but I don't see any reason why it should not work.

请注意,上述假设。如果你允许代码点0x80到0xFF,那么你不能使用UTF-8(或UTF-16当然)作为编码。

Note that the above assumes Latin / Windows 1252 compatible encoding for values 0x80 and over. If you allow code points of 0x80 to 0xFF then you cannot use UTF-8 (or UTF-16 of course) as encoding.

这篇关于JAVA:PBEKeySpec带有字节数组参数,而不是ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 13:33