public static byte[] convertJWSConcatenatedToDEREncodedSignature(final byte[] concatenatedSignatureValue) throws IOException {
  final byte[] r=new byte[33];
  final byte[] s=new byte[33];
  System.arraycopy(concatenatedSignatureValue,0,r,1,32);
  System.arraycopy(concatenatedSignatureValue,32,s,1,32);
  final BigInteger rBigInteger=new BigInteger(r);
  final BigInteger sBigInteger=new BigInteger(s);
  final ByteArrayOutputStream bos=new ByteArrayOutputStream();
  final DERSequenceGenerator seqGen=new DERSequenceGenerator(bos);
  seqGen.addObject(new ASN1Integer(rBigInteger.toByteArray()));
  seqGen.addObject(new ASN1Integer(sBigInteger.toByteArray()));
  seqGen.close();
  bos.close();
  final byte[] derEncodedSignatureValue=bos.toByteArray();
  return derEncodedSignatureValue;
}

public static byte [ ] convertJWSConcatenatedToDEREncodedSignature ( final byte [ ] concatenatedSignatureValue ) throws IOException { final byte [ ] r = new byte [ 33 ] ; final byte [ ] s = new byte [ 33 ] ; System . arraycopy ( concatenatedSignatureValue , 0 , r , 1 , 32 ) ; System . arraycopy ( concatenatedSignatureValue , 32 , s , 1 , 32 ) ; final BigInteger rBigInteger = new BigInteger ( r ) ; final BigInteger sBigInteger = new BigInteger ( s ) ; final ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; final DERSequenceGenerator seqGen = new DERSequenceGenerator ( bos ) ; seqGen . addObject ( new ASN1Integer ( rBigInteger . toByteArray ( ) ) ) ; seqGen . addObject ( new ASN1Integer ( sBigInteger . toByteArray ( ) ) ) ; seqGen . close ( ) ; bos . close ( ) ; final byte [ ] derEncodedSignatureValue = bos . toByteArray ( ) ; return derEncodedSignatureValue ; }
helper method to convert concatenated signature values ( as used by the jws - standard ) to der - encoded signature values ( e . g . used by java )
