code: public static String rsa256Sign(String content, String privateKey,
                                      String charset) throws AlipayApiException {
  
          try {
              PrivateKey priKey = getPrivateKeyFromPKCS8(AlipayConstants.SIGN_TYPE_RSA,
                  new ByteArrayInputStream(privateKey.getBytes()));
  
              java.security.Signature signature = java.security.Signature
                  .getInstance(AlipayConstants.SIGN_SHA256RSA_ALGORITHMS);
  
              signature.initSign(priKey);
  
              if (StringUtils.isEmpty(charset)) {
                  signature.update(content.getBytes());
              } else {
                  signature.update(content.getBytes(charset));
              }
  
              byte[] signed = signature.sign();
  
              return new String(Base64.encodeBase64(signed));
          } catch (Exception e) {
              throw new AlipayApiException("RSAcontent = " + content + "; charset = " + charset, e);
          }
  
      }
docs: sha256WithRsa 加签
  
  @param content
  @param privateKey
  @param charset
  @return
  @throws AlipayApiException