【发布时间】:2022-01-18 05:57:09
【问题描述】:
最近一段时间,我一直在尝试构建一个 Java 库来解释和验证 NZ Covid Pass。在签名验证之前,我已经让代码工作得更好或更糟(这个过程中一个稍微重要的部分)。里面的代码很完整is available here,不过还是比较粗糙。
验证器本身is available here、there is an accompying test。 Technical specification for the covid pass is here。 There are is at least one relevant section.
在与另一位开发人员合作后,我认为我已经确定了解释所提供的公钥。下面的代码(删除了调试输出)。 The public key details come from here
private PublicKey extractPublicKey(PublicKeysDetails publicKeyDetails) throws NoSuchAlgorithmException, InvalidParameterSpecException, InvalidKeySpecException {
byte[] xBytes = Base64.getDecoder().decode(publicKeyDetails.x().replace('-', '+').replace('_', '/'));
byte[] yBytes = Base64.getDecoder().decode(publicKeyDetails.y().replace('-', '+').replace('_', '/'));
BigInteger x = new BigInteger(xBytes);
BigInteger y = new BigInteger(yBytes);
ECPoint ecPoint = new ECPoint(x, y);
ECGenParameterSpec parameterSpec = new ECGenParameterSpec("secp256r1");//publicKeyDetails.crv() Should always come from the endpoint as "P-256", java wants to know exactly secp256r1, or NIST P-256
AlgorithmParameters parameters = AlgorithmParameters.getInstance("EC");//publicKeyDetails.kty() Should always come from the endpoint as "EC"
parameters.init(parameterSpec);
ECParameterSpec ecParameters = parameters.getParameterSpec(ECParameterSpec.class);
ECPublicKeySpec pubSpec = new ECPublicKeySpec(ecPoint, ecParameters);
KeyFactory kf = KeyFactory.getInstance("EC");
return kf.generatePublic(pubSpec);
}
该错误可能存在于该文件的其他位置,但我现在非常迷茫,不知道它可能是什么。
请帮我堆栈溢出你唯一的希望?
【问题讨论】:
标签: java validation signature ecdsa