我正在寻找一种方法来转换长字符串(从转储),它表示十六进制值到一个字节数组.
但为了保持原创,我会用自己的方式来表达它:假设我有一个"00A0BF"我想要解释为的字符串
byte[] {0x00,0xA0,0xBf}
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
我是Java新手,最后使用BigInteger并注意领先的十六进制零.但我觉得它很难看,我确信我错过了一些简单的东西.
我试图在Java中使用RSA编写加密算法,我得到一个"javax.crypto.BadPaddingException:数据必须从零开始"; 我不知道这个例外是什么.这是我在这里使用的例子
这是我的代码; 请帮忙.
public byte[] getEncryptedValue(byte[] bytes, PublicKey key) {
try {
cipher.init(Cipher.ENCRYPT_MODE, key);
return blockCipher(bytes, Cipher.ENCRYPT_MODE);
} catch (Exception ex) {
Logger.getLogger(SecurityUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public byte[] getDecryptedValue(byte[] bytes, PrivateKey key) {
try {
cipher.init(Cipher.DECRYPT_MODE, key);
return blockCipher(bytes, Cipher.DECRYPT_MODE);
} catch (Exception ex) {
Logger.getLogger(SecurityUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
private byte[] append(byte[] prefix, byte[] suffix) {
byte[] toReturn = new byte[prefix.length + suffix.length];
System.arraycopy(prefix, 0, toReturn, 0, prefix.length);
System.arraycopy(suffix, 0, toReturn, …Run Code Online (Sandbox Code Playgroud)