资源简介
利用jce简单实现了CBC-MAC算法,程序主要完成了子密钥生成算法、以及MAC的生成。
代码片段和文件信息
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public class CMAC {
private static final String fileName = “5070309654_徐京_实验报告3.pdf“;
private static int BLOCK_LEN;
private Cipher cipher;
private byte[] key;
private byte[] k1;
private byte[] k2;
public static void main(String[] args) throws Exception {
CMAC cmac = new CMAC();
cmac.init();
System.out.println(cmac.getMAC(new FileInputStream(fileName)));
}
private void init() throws Exception {
BLOCK_LEN = 16;
key = getKey(“507030965420101114“.getBytes());
cipher = Cipher.getInstance(“AES/CBC/noPadding“);
IvParameterSpec iv = new IvParameterSpec(key);
SecretKeySpec sk = new SecretKeySpec(key 0 BLOCK_LEN “AES“);
cipher.init(Cipher.ENCRYPT_MODE sk iv);
byte[] kl = cipher.update(new byte[BLOCK_LEN]);
k1 = getSubKey(kl);
k2 = getSubKey(k1);
}
/**
* 得到MAC
* @param cipher
* @param k1
* @param k2
* @param text
* @return
* @throws Exception
*/
private String getMAC(InputStream text) throws Exception {
byte[] cipherText = new byte[BLOCK_LEN];
byte[] current = new byte[BLOCK_LEN];
byte[] next = new byte[BLOCK_LEN];
int currentLen nextLen;
currentLen = text.read(current);
do {
nextLen = text.read(next);
if (nextLen != -1) {
cipherText = cipher.update(xor(current cipherText));
current = next;
currentLen = nextLen;
next = new byte[BLOCK_LEN];
nextLen = 0;
}
} while (nextLen != -1);
if (currentLen < BLOCK_LEN)
cipherText = cipher.update(xor(xor(padding(current currentLen) k2) cipherText));
else
- 上一篇:一个使用xutils上传图片到服务器的工具类
- 下一篇:java开发的公司访客系统
相关资源
- mac版adb工具
- Advanced Design and Implementation of Virtual
- JS实现AES-GCM加密,java实现AES-GCM解密。
- ModifiedJava6Install.pkg
- 完美使用RSA2结合AES对数据进行加密兼
- aes加密算法 五种模式
- PDMan数据库建模工具-MAC版本
- Android实现登录界面和功能
- RSA加密传输AES的key和iv js加密 java解
- 高性能AES256对称加解密,兼容Java、
- BouncyCastleProvider jar包
- 基于JSP + Tomact的实验室教学管理系统
- JD-GUI for mac(java反编译工具mac版本)
- smack-jar包
- Java使用winzipaes对zip文件的操作支持中
- DbWrench 数据库设计 软件破解补丁 fo
- Android IM之基于Openfire+Smack的聊天服务
- JavaSE7中文文档for Dash Mac
- IxChariot Endpoint Windows,LINUX ,macOS,
- MAC地址模拟打卡软件
- Dash for macOS 开发者必备API文档聚合
- 平安Mac地址模拟打卡软件
- TinyOS源码说明
- Pycharm汉化补丁,Mac亲测可用
- android使用AES加密对文件进行前中后三
- MAC版SAP GUI 750
- javafx_scenebuilder-2_0-macosx-universal.dmg
- Android SDK Build-tools 28.0.3.zip
- jdk-13.0.2_osx-x64_bin.dmg MAC
- sap gui 750 for mac
评论
共有 条评论