public static String signHmacSHA1 ( final String source , final String secret ) { try { final Mac mac = Mac . getInstance ( "HmacSHA1" ) ; mac . init ( new SecretKeySpec ( secret . getBytes ( "UTF-8" ) , "HmacSHA1" ) ) ; final byte [ ] signData = mac . doFinal ( source . getBytes ( "UTF-8" ) ) ; return new String ( Base64 . encodeBase64 ( signData ) , "UTF-8" ) ; } catch ( final Exception e ) { throw new RuntimeException ( "HMAC-SHA1 sign failed" , e ) ; } }
Signs the specified source string using the specified secret .