国标加密算法java代码_加密算法的java实现源码

{

d18c02628675d0a2c816449d98bda930.png

long

a

=

state[

0

], b

=

state[

1

], c

=

state[

2

], d

=

state[

3

];

d18c02628675d0a2c816449d98bda930.png

long

[] x

=

new

long

[

16

];

d18c02628675d0a2c816449d98bda930.png

d18c02628675d0a2c816449d98bda930.png  Decode(x, block,

64

);

d18c02628675d0a2c816449d98bda930.png

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif

/**/

/*

Round 1

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

FF(a, b, c, d, x[

0

], S11,

0xd76aa478L

);

/**/

/*

1

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

FF(d, a, b, c, x[

1

], S12,

0xe8c7b756L

);

/**/

/*

2

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

FF(c, d, a, b, x[

2

], S13,

0x242070dbL

);

/**/

/*

3

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

FF(b, c, d, a, x[

3

], S14,

0xc1bdceeeL

);

/**/

/*

4

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

FF(a, b, c, d, x[

4

], S11,

0xf57c0fafL

);

/**/

/*

5

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

FF(d, a, b, c, x[

5

], S12,

0x4787c62aL

);

/**/

/*

6

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

FF(c, d, a, b, x[

6

], S13,

0xa8304613L

);

/**/

/*

7

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

FF(b, c, d, a, x[

7

], S14,

0xfd469501L

);

/**/

/*

8

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

FF(a, b, c, d, x[

8

], S11,

0x698098d8L

);

/**/

/*

9

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

FF(d, a, b, c, x[

9

], S12,

0x8b44f7afL

);

/**/

/*

10

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

FF(c, d, a, b, x[

10

], S13,

0xffff5bb1L

);

/**/

/*

11

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

FF(b, c, d, a, x[

11

], S14,

0x895cd7beL

);

/**/

/*

12

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

FF(a, b, c, d, x[

12

], S11,

0x6b901122L

);

/**/

/*

13

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

FF(d, a, b, c, x[

13

], S12,

0xfd987193L

);

/**/

/*

14

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

FF(c, d, a, b, x[

14

], S13,

0xa679438eL

);

/**/

/*

15

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

FF(b, c, d, a, x[

15

], S14,

0x49b40821L

);

/**/

/*

16

*/

d18c02628675d0a2c816449d98bda930.png

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif

/**/

/*

Round 2

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

GG(a, b, c, d, x[

1

], S21,

0xf61e2562L

);

/**/

/*

17

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

GG(d, a, b, c, x[

6

], S22,

0xc040b340L

);

/**/

/*

18

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

GG(c, d, a, b, x[

11

], S23,

0x265e5a51L

);

/**/

/*

19

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

GG(b, c, d, a, x[

0

], S24,

0xe9b6c7aaL

);

/**/

/*

20

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

GG(a, b, c, d, x[

5

], S21,

0xd62f105dL

);

/**/

/*

21

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

GG(d, a, b, c, x[

10

], S22,

0x2441453L

);

/**/

/*

22

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

GG(c, d, a, b, x[

15

], S23,

0xd8a1e681L

);

/**/

/*

23

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

GG(b, c, d, a, x[

4

], S24,

0xe7d3fbc8L

);

/**/

/*

24

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

GG(a, b, c, d, x[

9

], S21,

0x21e1cde6L

);

/**/

/*

25

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

GG(d, a, b, c, x[

14

], S22,

0xc33707d6L

);

/**/

/*

26

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

GG(c, d, a, b, x[

3

], S23,

0xf4d50d87L

);

/**/

/*

27

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

GG(b, c, d, a, x[

8

], S24,

0x455a14edL

);

/**/

/*

28

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

GG(a, b, c, d, x[

13

], S21,

0xa9e3e905L

);

/**/

/*

29

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

GG(d, a, b, c, x[

2

], S22,

0xfcefa3f8L

);

/**/

/*

30

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

GG(c, d, a, b, x[

7

], S23,

0x676f02d9L

);

/**/

/*

31

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

GG(b, c, d, a, x[

12

], S24,

0x8d2a4c8aL

);

/**/

/*

32

*/

d18c02628675d0a2c816449d98bda930.png

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif

/**/

/*

Round 3

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

HH(a, b, c, d, x[

5

], S31,

0xfffa3942L

);

/**/

/*

33

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

HH(d, a, b, c, x[

8

], S32,

0x8771f681L

);

/**/

/*

34

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

HH(c, d, a, b, x[

11

], S33,

0x6d9d6122L

);

/**/

/*

35

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

HH(b, c, d, a, x[

14

], S34,

0xfde5380cL

);

/**/

/*

36

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

HH(a, b, c, d, x[

1

], S31,

0xa4beea44L

);

/**/

/*

37

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

HH(d, a, b, c, x[

4

], S32,

0x4bdecfa9L

);

/**/

/*

38

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

HH(c, d, a, b, x[

7

], S33,

0xf6bb4b60L

);

/**/

/*

39

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

HH(b, c, d, a, x[

10

], S34,

0xbebfbc70L

);

/**/

/*

40

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

HH(a, b, c, d, x[

13

], S31,

0x289b7ec6L

);

/**/

/*

41

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

HH(d, a, b, c, x[

0

], S32,

0xeaa127faL

);

/**/

/*

42

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

HH(c, d, a, b, x[

3

], S33,

0xd4ef3085L

);

/**/

/*

43

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

HH(b, c, d, a, x[

6

], S34,

0x4881d05L

);

/**/

/*

44

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

HH(a, b, c, d, x[

9

], S31,

0xd9d4d039L

);

/**/

/*

45

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

HH(d, a, b, c, x[

12

], S32,

0xe6db99e5L

);

/**/

/*

46

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

HH(c, d, a, b, x[

15

], S33,

0x1fa27cf8L

);

/**/

/*

47

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

HH(b, c, d, a, x[

2

], S34,

0xc4ac5665L

);

/**/

/*

48

*/

d18c02628675d0a2c816449d98bda930.png

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif

/**/

/*

Round 4

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

II(a, b, c, d, x[

0

], S41,

0xf4292244L

);

/**/

/*

49

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

II(d, a, b, c, x[

7

], S42,

0x432aff97L

);

/**/

/*

50

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

II(c, d, a, b, x[

14

], S43,

0xab9423a7L

);

/**/

/*

51

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

II(b, c, d, a, x[

5

], S44,

0xfc93a039L

);

/**/

/*

52

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

II(a, b, c, d, x[

12

], S41,

0x655b59c3L

);

/**/

/*

53

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

II(d, a, b, c, x[

3

], S42,

0x8f0ccc92L

);

/**/

/*

54

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

II(c, d, a, b, x[

10

], S43,

0xffeff47dL

);

/**/

/*

55

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

II(b, c, d, a, x[

1

], S44,

0x85845dd1L

);

/**/

/*

56

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

II(a, b, c, d, x[

8

], S41,

0x6fa87e4fL

);

/**/

/*

57

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

II(d, a, b, c, x[

15

], S42,

0xfe2ce6e0L

);

/**/

/*

58

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

II(c, d, a, b, x[

6

], S43,

0xa3014314L

);

/**/

/*

59

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

II(b, c, d, a, x[

13

], S44,

0x4e0811a1L

);

/**/

/*

60

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  a

=

II(a, b, c, d, x[

4

], S41,

0xf7537e82L

);

/**/

/*

61

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  d

=

II(d, a, b, c, x[

11

], S42,

0xbd3af235L

);

/**/

/*

62

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  c

=

II(c, d, a, b, x[

2

], S43,

0x2ad7d2bbL

);

/**/

/*

63

*/

97e794c86028c5f5b5461ae5ef440a4c.png

3c6cafce68eb941a00f1998f1d3d3aa6.gif  b

=

II(b, c, d, a, x[

9

], S44,

0xeb86d391L

);

/**/

/*

64

*/

d18c02628675d0a2c816449d98bda930.png

d18c02628675d0a2c816449d98bda930.png  state[

0

]

+=

a;

d18c02628675d0a2c816449d98bda930.png  state[

1

]

+=

b;

d18c02628675d0a2c816449d98bda930.png  state[

2

]

+=

c;

d18c02628675d0a2c816449d98bda930.png  state[

3

]

+=

d;

d18c02628675d0a2c816449d98bda930.png

ecedf933ec37d714bd4c2545da43add2.png }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
文件加密解密算法(Java源码) java,file,算法,加密解密,java源码 package com.crypto.encrypt; import java.security.SecureRandom; import java.io.*; import javax.crypto.spec.DESKeySpec; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.Cipher; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; import javax.crypto.NoSuchPaddingException; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import java.lang.reflect.Constructor; import java.security.spec.KeySpec; import java.lang.reflect.InvocationTargetException; public class EncryptData { private String keyfile=null; public EncryptData() { } public EncryptData(String keyfile) { this.keyfile=keyfile; } /** * 加密文件 * @param filename String 源路径 * @param filenamekey String 加密后的路径 */ public void createEncryptData(String filename,String filenamekey) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException, NoSuchPaddingException, InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException, IOException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException, IllegalStateException, IllegalBlockSizeException, BadPaddingException, NoSuchPaddingException, InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException, IOException { //验证keyfile if(keyfile==null || keyfile.equals("")) { throw new NullPointerException("无效的key文件路径"); } encryptData(filename,filenamekey); } /** * 加密类文件 * @param filename String 原始的类文件 * @param encryptfile String 加密后的类文件 * @throws IOException * @throws InvalidKeyException * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException * @throws NoSuchPaddingException * @throws NoSuchAlgorithmException * @throws BadPaddingException * @throws IllegalBlockSizeException * @throws IllegalStateException */ private void encryptData(String filename,String encryptfile) throws IOException, InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, NoSuchAlgorithmException, BadPaddingException, IllegalBlockSizeException, IllegalStateException, ClassNotFoundException, SecurityException, NoSuchMethodException, InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException { byte data[]=Util.readFile(filename); // 执行加密操作 byte encryptedClassData[] = getencryptData(data); // 保存加密后的文件,覆盖原有的类文件。 Util.writeFile(encryptedClassData,encryptfile); } /** * 直接获得加密数据 * @param bytes byte[] * @throws IllegalStateException * @throws IllegalBlockSizeException * @throws BadPaddingException * @throws InvalidKeyException * @throws NoSuchPaddingException * @throws InvalidKeySpecException * @throws NoSuchAlgorithmException * @throws InstantiationException * @throws IllegalAccessException * @throws IllegalArgumentException * @throws InvocationTargetException * @throws NoSuchMethodException * @throws SecurityException * @throws ClassNotFoundException * @throws IOException * @return byte[] */ public byte[] createEncryptData(byte[] bytes) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, NoSuchPaddingException, InvalidKeySpecException, NoSuchAlgorithmException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException, IOException { bytes=getencryptData(bytes); return bytes; } private byte[] getencryptData(byte[] bytes) throws IOException, ClassNotFoundException, SecurityException, NoSuchMethodException, InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IllegalStateException { // 产生一个可信任的随机数源 SecureRandom sr = new SecureRandom(); //从密钥文件key Filename中得到密钥数据 byte[] rawKeyData = Util.readFile(keyfile); // 从原始密钥数据创建DESKeySpec对象 Class classkeyspec=Class.forName(Util.getValue("keyspec")); Constructor constructor = classkeyspec.getConstructor(new Class[]{byte[].class}); KeySpec dks = (KeySpec) constructor.newInstance(new Object[]{rawKeyData}); // 创建一个密钥工厂,然后用它把DESKeySpec转换成SecretKey对象 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(Util.getAlgorithm()); SecretKey key = keyFactory.generateSecret(dks); // Cipher对象实际完成加密操作 Cipher cipher = Cipher.getInstance(Util.getAlgorithm()); // 用密钥初始化Cipher对象 cipher.init(Cipher.ENCRYPT_MODE, key, sr); // 执行加密操作 bytes = cipher.doFinal(bytes); // 返回字节数组 return bytes; } /** * 设置key文件路径 * @param keyfile String */ public void setKeyFile(String keyfile) { this.keyfile=keyfile; } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值