Code example for Mac

Methods: init

0
    public MacDigestManager(long ledgerId, byte[] passwd) throws GeneralSecurityException {
        super(ledgerId);
        byte[] macKey = genDigest("mac", passwd);
        SecretKeySpec keySpec = new SecretKeySpec(macKey, KEY_ALGORITHM);
        mac = Mac.getInstance(KEY_ALGORITHM);
        mac.init(keySpec);
         
         
    } 
 
    static byte[] genDigest(String pad, byte[] passwd) throws NoSuchAlgorithmException {
        MessageDigest digest = MessageDigest.getInstance(DIGEST_ALGORITHM);
        digest.update(pad.getBytes());
        digest.update(passwd);
                return digest.digest();
    } 
 
    @Override 
    int getMacCodeLength() { 
        return 20; 
    }