Can';t用java制作ES256 JWT

Can';t用java制作ES256 JWT,java,spring,jwt,sha256,Java,Spring,Jwt,Sha256,我不能使用ES256算法制作JWT,我不知道为什么。 这是我的密码: Map headerMap=newhashmap(); 头映射放置(“孩子”,keyId); 总资产负债表(“alg”、“ES256”); 总资产负债表(“典型”、“JWT”); Map claimap=newhashmap(); claimMap.put(“iss”,团队ID); claimap.put(“iat”,nowTime.getTime()); claimap.put(“exp”,expTime); 分类存托凭证(

我不能使用ES256算法制作JWT,我不知道为什么。 这是我的密码:

Map headerMap=newhashmap();
头映射放置(“孩子”,keyId);
总资产负债表(“alg”、“ES256”);
总资产负债表(“典型”、“JWT”);
Map claimap=newhashmap();
claimMap.put(“iss”,团队ID);
claimap.put(“iat”,nowTime.getTime());
claimap.put(“exp”,expTime);
分类存托凭证(“澳元”,appleDomain);
claimap.put(“sub”,clientId);
SignatureAlgorithm SignatureAlgorithm=SignatureAlgorithm.ES256;
byte[]apiKeySecretBytes=DatatypeConverter.parseBase64Binary(getKey());
Key signingKey=newsecretkeyspec(apiKeySecretBytes,signatureAlgorithm.getJcaName());
字符串jwt=Jwts.builder()
.signWith(SignatureGorithm,signingKey)
.setClaims(CLAIMAP)
.setHeader(headerMap).compact();
java.lang.IllegalArgumentException:椭圆曲线签名必须使用EC私钥计算。javax.crypto.spec.SecretKeySpec类型的指定密钥不是EC PrivateKey。
位于io.jsonwebtoken.impl.crypto.EllipticCurveSigner。(EllipticCurveSigner.java:36)
位于io.jsonwebtoken.impl.crypto.DefaultSignerFactory.createSigner(DefaultSignerFactory.java:47)
位于io.jsonwebtoken.impl.crypto.DefaultJwtSigner。(DefaultJwtSigner.java:37)
位于io.jsonwebtoken.impl.crypto.DefaultJwtSigner。(DefaultJwtSigner.java:32)
位于io.jsonwebtoken.impl.DefaultJwtBuilder.createSigner(DefaultJwtBuilder.java:338)
位于io.jsonwebtoken.impl.DefaultJwtBuilder.compact(DefaultJwtBuilder.java:320)

如何使用p8密钥文件使用EC私钥(它来自apple,用于使用auth api)?

您知道p8文件中的密钥类型吗?有不同类型的密钥和不同类型的密码算法。我会说你可能有一个RSA密钥对而不是EC密钥对


我建议使用创建一个新密钥并将其添加到密钥库。

我从apple developer T下载了它。您的意思是此密钥文件不适用于ES256吗?是的。您可以安装密钥库资源管理器并检查您拥有的密钥类型。您好SUNA JO,您解决了吗?
java.lang.IllegalArgumentException: Elliptic Curve signatures must be computed using an EC PrivateKey.  The specified key of type javax.crypto.spec.SecretKeySpec is not an EC PrivateKey.
at io.jsonwebtoken.impl.crypto.EllipticCurveSigner.<init>(EllipticCurveSigner.java:36)
at io.jsonwebtoken.impl.crypto.DefaultSignerFactory.createSigner(DefaultSignerFactory.java:47)
at io.jsonwebtoken.impl.crypto.DefaultJwtSigner.<init>(DefaultJwtSigner.java:37)
at io.jsonwebtoken.impl.crypto.DefaultJwtSigner.<init>(DefaultJwtSigner.java:32)
at io.jsonwebtoken.impl.DefaultJwtBuilder.createSigner(DefaultJwtBuilder.java:338)
at io.jsonwebtoken.impl.DefaultJwtBuilder.compact(DefaultJwtBuilder.java:320)