The server code is correct. I'm using it in external signature with iText,and it works fine. I think the problem is with the bytes that are returned from sign method, because i saw in another examples that sign method returns CMSSignedDate.getEncoded(), which is actually the ASN.1 encoded representation. I tried this, but the byte array returned with Base64.decode(signature) is not what CMSSignedData constructor is expecting.. CMSSignedData cms=new CMSSignedData(Base64.decode(signature));
return cms.getEncoded();