Java SHA256withRSA 数字签名,用于带十进制值的字符串
我必须获取 json 有效负载作为输入,并使用 SHA256withRSA 对其进行签名。 我试图将 json 转换为 java object ,首先当值具有 Integer 类型时,签名是正确的,但是当我将类型更改为 Double 因为它是 amount 时,生成的签名字符串变得错误。
byte[] b1 = Base64.getDecoder().decode(realPK);
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(b1);
KeyFactory kf = KeyFactory.getInstance("RSA");
Signature privateSignature = Signature.getInstance("SHA256withRSA");
privateSignature.initSign(kf.generatePrivate(spec));
privateSignature.update(input.getBytes("UTF-8"));
byte[] s = privateSignature.sign();
return Base64.getEncoder().encodeToString(s);
}
Java对象
public class EmloyeeRecord {
......
@NotNull(message = "BasicSalary 不应为空")< /代码>
@JsonProperty("BasicSalary")
公共双倍基本工资;
<代码>... }
Json 负载
"FileRecordRq": [
<代码>{ <代码>.... “基本工资”:378880.00,
<代码>.... <代码>}
I have to get as input a json payload and sign it with SHA256withRSA .
I'm trying to convert the json to java object , first when the value has an Integer type, the signature was correct but when I changed the type to Double as it is an amount , the generated signature string become wrong.
byte[] b1 = Base64.getDecoder().decode(realPK);
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(b1);
KeyFactory kf = KeyFactory.getInstance("RSA");
Signature privateSignature = Signature.getInstance("SHA256withRSA");
privateSignature.initSign(kf.generatePrivate(spec));
privateSignature.update(input.getBytes("UTF-8"));
byte[] s = privateSignature.sign();
return Base64.getEncoder().encodeToString(s);
}
Java Object
public class EmloyeeRecord {
......
@NotNull(message = "BasicSalary should not be empty")
@JsonProperty("BasicSalary")
public Double basicSalary;
...
}
Json Payload
"FileRecordRq": [
{
....
"BasicSalary": 378880.00,
....
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论