Code example for Mac

Methods: init

0
        if (secret == null) {
            mac = null;
        } else { 
            mac = Mac.getInstance("HmacSHA1");
            byte[] keyBytes = secret.getBytes("UTF8");
            mac.init(new SecretKeySpec(keyBytes, "HmacSHA1"));
        } 
    } 
 
    /** 
     * Creates a signature for a given String. 
     * @param data The String to create the signature for. 
     * @return The signature. 
     * @throws Exception If an error occurs creating the signature. 
     */ 
    public String sign(String data) throws Exception {
        if (mac == null) {
            return null; 
        } 
 
Contextual code suggestions in your IDE  Get Codota for Java