public static String signUsingRsaSha256(
      PrivateKey privateKey,
      JsonFactory jsonFactory,
      JsonWebSignature.Header header,
      JsonWebToken.Payload payload)
      throws GeneralSecurityException, IOException {
    String content =
        Base64.encodeBase64URLSafeString(jsonFactory.toByteArray(header))
            + "."
            + Base64.encodeBase64URLSafeString(jsonFactory.toByteArray(payload));
    byte[] contentBytes = StringUtils.getBytesUtf8(content);
    byte[] signature =
        SecurityUtils.sign(
            SecurityUtils.getSha256WithRsaSignatureAlgorithm(), privateKey, contentBytes);
    return content + "." + Base64.encodeBase64URLSafeString(signature);
  }
public static String signUsingRsaSha256 ( PrivateKey privateKey , JsonFactory jsonFactory , JsonWebSignature . Header header , JsonWebToken . Payload payload ) throws GeneralSecurityException , IOException { String content = Base64 . encodeBase64URLSafeString ( jsonFactory . toByteArray ( header ) ) + "." + Base64 . encodeBase64URLSafeString ( jsonFactory . toByteArray ( payload ) ) ; byte [ ] contentBytes = StringUtils . getBytesUtf8 ( content ) ; byte [ ] signature = SecurityUtils . sign ( SecurityUtils . getSha256WithRsaSignatureAlgorithm ( ) , privateKey , contentBytes ) ; return content + "." + Base64 . encodeBase64URLSafeString ( signature ) ; }
Signs a given JWS header and payload based on the given private key using RSA and SHA-256 as
described in <a
href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#appendix-A.2">JWS using
RSA SHA-256</a>.

@param privateKey private key
@param jsonFactory JSON factory
@param header JWS header
@param payload JWS payload
@return signed JWS string
@since 1.14 (since 1.7 as com.google.api.client.auth.jsontoken.RsaSHA256Signer)