对比新文件 |
| | |
| | | |
| | | |
| | | package com.flow.util; |
| | | |
| | | import java.io.IOException; |
| | | import java.security.Security; |
| | | import java.text.ParseException; |
| | | import java.util.Base64; |
| | | import javax.crypto.Mac; |
| | | import javax.crypto.SecretKey; |
| | | import javax.crypto.spec.SecretKeySpec; |
| | | import org.bouncycastle.crypto.RuntimeCryptoException; |
| | | import org.bouncycastle.jce.provider.BouncyCastleProvider; |
| | | |
| | | public class HmacSHA256 { |
| | | public HmacSHA256() { |
| | | } |
| | | |
| | | public static String encrytSHA256(String content, String secret) { |
| | | try { |
| | | Security.addProvider(new BouncyCastleProvider()); |
| | | SecretKey secretKey = new SecretKeySpec(secret.getBytes("UTF8"), "HmacSHA256"); |
| | | Mac mac = Mac.getInstance(secretKey.getAlgorithm()); |
| | | mac.init(secretKey); |
| | | byte[] digest = mac.doFinal(content.getBytes("UTF-8")); |
| | | String var5 = Base64.getEncoder().encodeToString(digest); |
| | | return content; |
| | | } catch (Exception var6) { |
| | | throw new RuntimeCryptoException("鍔犲瘑寮傚父"); |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) throws ParseException, IOException { |
| | | System.out.println(encrytSHA256("鍔犲瘑鍐呭", "key")); |
| | | } |
| | | } |