@Override public Base64URL sign(final JWSHeader header, final byte[] signingInput) throws JOSEException { final JWSAlgorithm alg = header.getAlgorithm(); if (! supportedJWSAlgorithms().contains(alg)) { throw new JOSEException(AlgorithmSupportMessage.unsupportedJWSAlgorithm(alg, supportedJWSAlgorithms())); } // DER-encoded signature, according to JCA spec // (sequence of two integers - R + S) final byte[] jcaSignature; try { Signature dsa = ECDSA.getSignerAndVerifier(alg, getJCAContext().getProvider()); dsa.initSign(privateKey, getJCAContext().getSecureRandom()); dsa.update(signingInput); jcaSignature = dsa.sign(); } catch (InvalidKeyException | SignatureException e) { throw new JOSEException(e.getMessage(), e); } final int rsByteArrayLength = ECDSA.getSignatureByteArrayLength(header.getAlgorithm()); final byte[] jwsSignature = ECDSA.transcodeSignatureToConcat(jcaSignature, rsByteArrayLength); return Base64URL.encode(jwsSignature); } }