@Test void create_with_signature_test() { JWSHeader header = new JWSHeader(JWAIdentifier.ES256, TestAttestationUtil.load3tierTestAttestationCertificatePath()); Payload payload = new Payload(); byte[] signature = new byte[32]; JWS<Payload> jws = target.create(header, payload, signature); assertThat(jws).isNotNull(); }
public <T extends Serializable> JWS<T> create(JWSHeader header, T payload, PrivateKey privateKey) { String headerString = Base64UrlUtil.encodeToString(jsonConverter.writeValueAsString(header).getBytes(StandardCharsets.UTF_8)); String payloadString = Base64UrlUtil.encodeToString(jsonConverter.writeValueAsString(payload).getBytes(StandardCharsets.UTF_8)); String signedData = headerString + "." + payloadString; Signature signatureObj = SignatureUtil.createSignature(header.getAlg().getJcaName()); try { signatureObj.initSign(privateKey); signatureObj.update(signedData.getBytes()); byte[] derSignature = signatureObj.sign(); byte[] jwsSignature = JWSSignatureUtil.convertDerSignatureToJwsSignature(derSignature); return new JWS<>(header, headerString, payload, payloadString, jwsSignature); } catch (InvalidKeyException | SignatureException e) { throw new IllegalArgumentException(e); } }
JWSFactory { public <T extends Serializable> JWS<T> create(JWSHeader header, T payload, PrivateKey privateKey) { String headerString = Base64UrlUtil.encodeToString(jsonConverter.writeValueAsString(header).getBytes(StandardCharsets.UTF_8)); String payloadString = Base64UrlUtil.encodeToString(jsonConverter.writeValueAsString(payload).getBytes(StandardCharsets.UTF_8)); String signedData = headerString + "." + payloadString; Signature signatureObj = SignatureUtil.createSignature(header.getAlg().getJcaName()); try { signatureObj.initSign(privateKey); signatureObj.update(signedData.getBytes()); byte[] derSignature = signatureObj.sign(); byte[] jwsSignature = JWSSignatureUtil.convertDerSignatureToJwsSignature(derSignature); return new JWS<>(header, headerString, payload, payloadString, jwsSignature); } catch (InvalidKeyException | SignatureException e) { throw new IllegalArgumentException(e); } } }
JWSFactory { public <T extends Serializable> JWS<T> create(JWSHeader header, T payload, PrivateKey privateKey) { String headerString = Base64UrlUtil.encodeToString(jsonConverter.writeValueAsString(header).getBytes(StandardCharsets.UTF_8)); String payloadString = Base64UrlUtil.encodeToString(jsonConverter.writeValueAsString(payload).getBytes(StandardCharsets.UTF_8)); String signedData = headerString + "." + payloadString; Signature signatureObj = SignatureUtil.createSignature(header.getAlg().getJcaName()); try { signatureObj.initSign(privateKey); signatureObj.update(signedData.getBytes()); byte[] derSignature = signatureObj.sign(); byte[] jwsSignature = JWSSignatureUtil.convertDerSignatureToJwsSignature(derSignature); return new JWS<>(header, headerString, payload, payloadString, jwsSignature); } catch (InvalidKeyException | SignatureException e) { throw new IllegalArgumentException(e); } } JWSFactory(ObjectConverter objectConverter);  JWSFactory(); }
JWSFactory { public <T extends Serializable> JWS<T> create(JWSHeader header, T payload, PrivateKey privateKey) { String headerString = Base64UrlUtil.encodeToString(jsonConverter.writeValueAsString(header).getBytes(StandardCharsets.UTF_8)); String payloadString = Base64UrlUtil.encodeToString(jsonConverter.writeValueAsString(payload).getBytes(StandardCharsets.UTF_8)); String signedData = headerString + "." + payloadString; Signature signatureObj = SignatureUtil.createSignature(header.getAlg().getJcaName()); try { signatureObj.initSign(privateKey); signatureObj.update(signedData.getBytes()); byte[] derSignature = signatureObj.sign(); byte[] jwsSignature = JWSSignatureUtil.convertDerSignatureToJwsSignature(derSignature); return new JWS<>(header, headerString, payload, payloadString, jwsSignature); } catch (InvalidKeyException | SignatureException e) { throw new IllegalArgumentException(e); } } JWSFactory(ObjectConverter objectConverter);  JWSFactory(); JWS<T> create(JWSHeader header, T payload, PrivateKey privateKey); JWS<T> create(JWSHeader header, T payload, byte[] signature); JWS<T> parse(String value, Class<T> payloadType); }
JWSFactory { public <T extends Serializable> JWS<T> create(JWSHeader header, T payload, PrivateKey privateKey) { String headerString = Base64UrlUtil.encodeToString(jsonConverter.writeValueAsString(header).getBytes(StandardCharsets.UTF_8)); String payloadString = Base64UrlUtil.encodeToString(jsonConverter.writeValueAsString(payload).getBytes(StandardCharsets.UTF_8)); String signedData = headerString + "." + payloadString; Signature signatureObj = SignatureUtil.createSignature(header.getAlg().getJcaName()); try { signatureObj.initSign(privateKey); signatureObj.update(signedData.getBytes()); byte[] derSignature = signatureObj.sign(); byte[] jwsSignature = JWSSignatureUtil.convertDerSignatureToJwsSignature(derSignature); return new JWS<>(header, headerString, payload, payloadString, jwsSignature); } catch (InvalidKeyException | SignatureException e) { throw new IllegalArgumentException(e); } } JWSFactory(ObjectConverter objectConverter);  JWSFactory(); JWS<T> create(JWSHeader header, T payload, PrivateKey privateKey); JWS<T> create(JWSHeader header, T payload, byte[] signature); JWS<T> parse(String value, Class<T> payloadType);  }