//$Id: Rijndael_Algorithm.java,v 1.1 2001/05/21 02:24:30 jis Exp $
//
// $Log: Rijndael_Algorithm.java,v $
// Revision 1.1 2001/05/21 02:24:30 jis
// First version
//
// Revision 1.1 1998/04/12 Paulo
// + optimized methods for the default 128-bit block size.
//
// Revision 1.0 1998/03/11 Raif
// + original version.
//
// $Endlog$
/*
* Copyright (c) 1997, 1998 Systemics Ltd on behalf of
* the Cryptix Development Team. All rights reserved.
*/
package cn.thinknet.utils.encrypt;
import java.security.InvalidKeyException;
/*
* 加密算法规则类
*
* @author 李时增
*
* CreateTime:2013-12-02
*/
public final class AESAlgorithm
{
// Debugging methods and variables
// ...........................................................................
static final String NAME = "Rijndael_Algorithm";
static final boolean IN = true, OUT = false;
// Constants and variables
// ...........................................................................
static final int BLOCK_SIZE = 16; // default block size in bytes
static final int[] alog = new int[256];
static final int[] log = new int[256];
static final byte[] S = new byte[256];
static final byte[] Si = new byte[256];
static final int[] T1 = new int[256];
static final int[] T2 = new int[256];
static final int[] T3 = new int[256];
static final int[] T4 = new int[256];
static final int[] T5 = new int[256];
static final int[] T6 = new int[256];
static final int[] T7 = new int[256];
static final int[] T8 = new int[256];
static final int[] U1 = new int[256];
static final int[] U2 = new int[256];
static final int[] U3 = new int[256];
static final int[] U4 = new int[256];
static final byte[] rcon = new byte[30];
static final int[][][] shifts = new int[][][]
{
{
{ 0, 0 },
{ 1, 3 },
{ 2, 2 },
{ 3, 1 } },
{
{ 0, 0 },
{ 1, 5 },
{ 2, 4 },
{ 3, 3 } },
{
{ 0, 0 },
{ 1, 7 },
{ 3, 5 },
{ 4, 4 } } };
// Static code - to intialise S-boxes and T-boxes
// ...........................................................................
static
{
long time = System.currentTimeMillis();
int ROOT = 0x11B;
int i, j = 0;
//
// produce log and alog tables, needed for multiplying in the
// field GF(2^m) (generator = 3)
//
alog[0] = 1;
for (i = 1; i < 256; i++)
{
j = (alog[i - 1] << 1) ^ alog[i - 1];
if ((j & 0x100) != 0)
j ^= ROOT;
alog[i] = j;
}
for (i = 1; i < 255; i++)
log[alog[i]] = i;
byte[][] A = new byte[][]
{
{ 1, 1, 1, 1, 1, 0, 0, 0 },
{ 0, 1, 1, 1, 1, 1, 0, 0 },
{ 0, 0, 1, 1, 1, 1, 1, 0 },
{ 0, 0, 0, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 1, 1, 1, 1 },
{ 1, 1, 0, 0, 0, 1, 1, 1 },
{ 1, 1, 1, 0, 0, 0, 1, 1 },
{ 1, 1, 1, 1, 0, 0, 0, 1 } };
byte[] B = new byte[]
{ 0, 1, 1, 0, 0, 0, 1, 1 };
//
// substitution box based on F^{-1}(x)
//
int t;
byte[][] box = new byte[256][8];
box[1][7] = 1;
for (i = 2; i < 256; i++)
{
j = alog[255 - log[i]];
for (t = 0; t < 8; t++)
box[i][t] = (byte) ((j >>> (7 - t)) & 0x01);
}
//
// affine transform: box[i] <- B + A*box[i]
//
byte[][] cox = new byte[256][8];
for (i = 0; i < 256; i++)
for (t = 0; t < 8; t++)
{
cox[i][t] = B[t];
for (j = 0; j < 8; j++)
cox[i][t] ^= A[t][j] * box[i][j];
}
//
// S-boxes and inverse S-boxes
//
for (i = 0; i < 256; i++)
{
S[i] = (byte) (cox[i][0] << 7);
for (t = 1; t < 8; t++)
S[i] ^= cox[i][t] << (7 - t);
Si[S[i] & 0xFF] = (byte) i;
}
//
// T-boxes
//
byte[][] G = new byte[][]
{
{ 2, 1, 1, 3 },
{ 3, 2, 1, 1 },
{ 1, 3, 2, 1 },
{ 1, 1, 3, 2 } };
byte[][] AA = new byte[4][8];
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
AA[i][j] = G[i][j];
AA[i][i + 4] = 1;
}
byte pivot, tmp;
byte[][] iG = new byte[4][4];
for (i = 0; i < 4; i++)
{
pivot = AA[i][i];
if (pivot == 0)
{
t = i + 1;
while ((AA[t][i] == 0) && (t < 4))
t++;
if (t == 4)
throw new RuntimeException("G matrix is not invertible");
else
{
for (j = 0; j < 8; j++)
{
tmp = AA[i][j];
AA[i][j] = AA[t][j];
AA[t][j] = (byte) tmp;
}
pivot = AA[i][i];
}
}
for (j = 0; j < 8; j++)
if (AA[i][j] != 0)
AA[i][j] = (byte) alog[(255 + log[AA[i][j] & 0xFF] - log[pivot & 0xFF]) % 255];
for (t = 0; t < 4; t++)
if (i != t)
{
for (j = i + 1; j < 8; j++)
AA[t][j] ^= mul(AA[i][j], AA[t][i]);
AA[t][i] = 0;
}
}
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
iG[i][j] = AA[i][j + 4];
int s;
for (t = 0; t < 256; t++)
{
s = S[t];
T1[t] = mul4(s, G[0]);
T2[t] = mul4(s, G[1]);
T3[t] = mul4(s, G[2]);
T4[t] = mul4(s, G[3]);
s = Si[t];
T5[t] = mul4(s, iG[0]);
T6[t] = mul4(s, iG[1]);
T7[t] = mul4(s, iG[2]);
T8[t] = mul4(s, iG[3]);
U1[t] = mul4(t, iG[0]);
U2[t] = mul4(t, iG[1]);
U3[t] = mul4(t, iG[2]);
U4[t] = mul4(t, iG[3]);
}
//
// round constants
//
rcon[0] = 1;
int r = 1;
for (t = 1; t < 30;)
rcon[t++] = (byte) (r = mul(2, r));
time = System.currentTimeMillis() - time;
}
// multiply two elements of GF(2^m)
static final int mul(int a, int b)
{
return (a != 0 && b != 0) ? alog[(log[a & 0xFF] + log[b & 0xFF]) % 255]
: 0;
}
// convenience method used in generating Transposition boxes
static final int mul4(int a, byte[] b)
{
if (a == 0)
return 0;
a = log[a & 0xFF];
int a0 = (b[0] != 0) ? alog[(a + log[b[0] & 0xFF]) % 255] & 0xFF : 0;
int a1 = (b[1] != 0) ? alog[(a + log[b[1] & 0xFF]) % 255] & 0xFF : 0;
int a2 = (b[2] != 0) ? alog[(a + log[b[2] & 0xFF]) % 255] & 0xFF : 0;
int a3 = (b[3] != 0) ? alog[(a + log[b[3] & 0xFF]) % 255] & 0xFF : 0;
return a0 << 24 | a1 << 16 | a2 << 8 | a3;
}
// Basic API methods
// ...........................................................................
/**
* Convenience method to expand a user-supplied key material into a session
* key, assuming Rijndael's default block size (128-bit).
*
* @param key The 128/192/256-bit user-key to use.
* @exception InvalidKeyException If the key is invalid.
*/
public static Object makeKey(byte[] k) throws InvalidKeyException
{
return makeKey(k, BLOCK_SIZE)
没有合适的资源?快使用搜索试试~ 我知道了~
SpringMvc 二维码简易实现Dome
共928个文件
js:338个
css:188个
png:180个
4星 · 超过85%的资源 需积分: 9 137 下载量 75 浏览量
2016-11-24
14:54:37
上传
评论 3
收藏 19.58MB ZIP 举报
温馨提示
SpringMvc的实现,
资源推荐
资源详情
资源评论
收起资源包目录
SpringMvc 二维码简易实现Dome (928个子文件)
applicationContext.xml.bak 6KB
AESAlgorithm.class 13KB
AKPagination.class 6KB
TwoDimensionCode.class 6KB
SignUtil.class 5KB
AKAjaxPagination.class 5KB
WxUtil.class 5KB
AESObject.class 5KB
AKKeysUtil.class 4KB
MD5Util.class 4KB
WeixinUtil.class 4KB
MapJsonToolsUtil.class 4KB
DefaultBaseDaoImpl.class 4KB
Sign.class 3KB
StringHelper.class 3KB
WxPropertiesUtil.class 3KB
AKFileUtil.class 3KB
JSONFormatter.class 3KB
ErwmControl.class 2KB
AKMap.class 2KB
HttpGetRequest.class 2KB
AESBase64.class 2KB
DateUtil.class 2KB
PageVo.class 2KB
JsonDateValueProcessor.class 2KB
DateJsonValueProcessor.class 1KB
AKLoggerUtil.class 1KB
Config.class 1KB
TicketJson.class 1KB
BatisBaseDao.class 1KB
TwoDimensionCodeImage.class 844B
TokenJson.class 803B
AccessToken.class 777B
Ticket.class 765B
JSONFormatter$1.class 742B
WxParams.class 441B
.classpath 6KB
org.eclipse.wst.common.component 467B
org.eclipse.wst.jsdt.ui.superType.container 49B
jquery.mobile-1.4.5.css 240KB
jquery.mobile-1.4.5.min.css 203KB
bootstrap.css 127KB
bootstrap.min.css 117KB
easyui.css 51KB
easyui.css 51KB
easyui.css 51KB
easyui.css 50KB
editor_ie7.css 48KB
easyui.css 47KB
editor_iequirks.css 47KB
editor_ie8.css 46KB
editor_ie.css 46KB
editor_gecko.css 45KB
editor.css 45KB
bootstrap-theme.css 43KB
styles.css 33KB
easyui1.css 32KB
jquery-ui.min.css 28KB
dialog_ie7.css 17KB
dialog_ie8.css 17KB
dialog_iequirks.css 16KB
dialog_ie.css 16KB
dialog.css 16KB
layer.css 14KB
theme.css 13KB
mobiscroll.animation-2.5.2.css 13KB
mobiscroll.core-2.5.2.css 9KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 6KB
mobiscroll.android-ics-2.5.2.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datepicker.css 5KB
datepicker.css 5KB
datagrid.css 5KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
color.css 4KB
global.css 4KB
datepicker.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
datepicker.css 4KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
panel.css 3KB
共 928 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
- Alvin_何2017-08-22亲测下载直接运行,二维码可以生成
- ecnukobe20102017-08-24厉害啊!!
- duolaA098762017-09-26还没用,还是很感谢!
- ccnewer2018-09-21看看了代码 !!!
鱼遇上了猫
- 粉丝: 58
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功