SHARE
TWEET

Untitled

a guest Aug 19th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private static final String SIGN_ALGORITHMS = "MD5WithRSA";
  2.  
  3.     public static String sign(String content, String privateKey, String input_charset) {
  4.             try {
  5.                 PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(privateKey));
  6.                 KeyFactory keyf = KeyFactory.getInstance("RSA");
  7.                 PrivateKey priKey = keyf.generatePrivate(priPKCS8);
  8.                 java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);
  9.                 signature.initSign(priKey);
  10.                 signature.update(content.getBytes(input_charset));
  11.                 byte[] signed = signature.sign();
  12.                 return Base64.encode(signed);
  13.             } catch (Exception e) {
  14.                 e.printStackTrace();
  15.             }
  16.  
  17.             return null;
  18.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top