⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e469. generating a message authentication code (mac).txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
A MAC is like hash code for a sequence of bytes. Unlike a hash code, a MAC uses a secret key to generate the hash code, or more specifically, the message digest. A MAC is generally used to check the integrity or validity of information based on a secret key. 
    try {
        // Generate a key for the HMAC-MD5 keyed-hashing algorithm; see RFC 2104
        // In practice, you would save this key.
        KeyGenerator keyGen = KeyGenerator.getInstance("HmacMD5");
        SecretKey key = keyGen.generateKey();
    
        // Create a MAC object using HMAC-MD5 and initialize with key
        Mac mac = Mac.getInstance(key.getAlgorithm());
        mac.init(key);
    
        String str = "This message will be digested";
    
        // Encode the string into bytes using utf-8 and digest it
        byte[] utf8 = str.getBytes("UTF8");
        byte[] digest = mac.doFinal(utf8);
    
        // If desired, convert the digest into a string
        String digestB64 = new sun.misc.BASE64Encoder().encode(digest);
    } catch (InvalidKeyException e) {
    } catch (NoSuchAlgorithmException e) {
    } catch (UnsupportedEncodingException e) {
    }


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -