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