修改 sdf 调用风格
This commit is contained in:
parent
249d857dc1
commit
f0fcd05acf
@ -108,33 +108,34 @@ public class OpenApiService implements IOpenApiService {
|
||||
byte[] hash = new byte[32]; // SM3 哈希长度为 32 字节
|
||||
IntByReference hashLength = new IntByReference();
|
||||
|
||||
// 使用空指针作为会话句柄(SDFSoft 支持)
|
||||
Pointer sessionHandle = Pointer.NULL;
|
||||
|
||||
// 默认的 SM2 用户 ID(与签名时保持一致)
|
||||
String userId = "1234567812345678";
|
||||
final String userId = "1234567812345678";
|
||||
|
||||
// 初始化哈希(包含公钥和用户 ID)
|
||||
int ret = sdf.SDF_HashInit(sessionHandle, 0, publicKey, userId, userId.length());
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
return sessionTemplate.withSession("SM2Verify", (sdf, deviceHandle, sessionHandle) -> {
|
||||
|
||||
// 更新哈希(添加原始数据)
|
||||
ret = sdf.SDF_HashUpdate(sessionHandle, origBytes, origBytes.length);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
// 初始化哈希(包含公钥和用户 ID)
|
||||
sessionTemplate.ensureSuccess(
|
||||
"SDF_HashInit",
|
||||
sdf.SDF_HashInit(sessionHandle, 0, publicKey, userId.getBytes(), 16)
|
||||
);
|
||||
|
||||
// 完成哈希
|
||||
ret = sdf.SDF_HashFinal(sessionHandle, hash, hashLength);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
// 更新哈希(添加原始数据)
|
||||
sessionTemplate.ensureSuccess(
|
||||
"SDF_HashUpdate",
|
||||
sdf.SDF_HashUpdate(sessionHandle, origBytes, origBytes.length)
|
||||
);
|
||||
|
||||
// 完成哈希
|
||||
sessionTemplate.ensureSuccess(
|
||||
"SDF_HashFinal",
|
||||
sdf.SDF_HashFinal(sessionHandle, hash, hashLength)
|
||||
);
|
||||
|
||||
// 使用 SDF 接口进行 SM2 验签
|
||||
int ret = sdf.SDF_ExternalVerify_ECC(sessionHandle, 0, publicKey, hash, hashLength.getValue(), signature);
|
||||
return ret == 0;
|
||||
});
|
||||
|
||||
// 使用 SDF 接口进行 SM2 验签
|
||||
ret = sdf.SDF_ExternalVerify_ECC(sessionHandle, 0, publicKey, hash, hashLength.getValue(), signature);
|
||||
return ret == 0;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user