转载大神的
https://blog.csdn.net/want_water_fish/article/details/73498692
加密算法:
1.单项加密
2.对称加密
3.非对称加密 简单解释为--》公开秘钥加密,私有秘钥解密。或者相反使用
https://www.cnblogs.com/yx520zhao/p/6658688.html
oracle中实现DES加密解密和MD5加密
https://blog.csdn.net/xdweleven/article/details/38319351
package main;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base32;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
public class CryptoUtil {
public static Key DEFAULT_KEY = null;
public static final String DEFAULT_SECRET_KEY1 = "?:P)(OL><KI*&UJMNHY^%TGBVFR$#EDCXSW@!QAZ";
public static final String DEFAULT_SECRET_KEY2 = "1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik,9ol.0p;/";
public static final String DEFAULT_SECRET_KEY3 = "!QAZ@WSX#EDC$RFV%TGB^YHN&UJM*IK<(OL>)P:?";
public static final String DEFAULT_SECRET_KEY4 = "1qaz@WSX3edc$RFV5tgb^YHN7ujm*IK<9ol.)P:?";
public static final String DEFAULT_SECRET_KEY5 = "!QAZ2wsx#EDC4rfv%TGB6yhn&UJM8ik,(OL>0p;/";
public static final String DEFAULT_SECRET_KEY6 = "1qaz2wsx3edc4rfv5tgb^YHN&UJM*IK<(OL>)P:?";
public static final String DEFAULT_SECRET_KEY = DEFAULT_SECRET_KEY1;
public static final String DES = "DES";
public static final Base32 base32 = new Base32();
static {
DEFAULT_KEY = obtainKey(DEFAULT_SECRET_KEY);
}
/**
* 获得key
**/
public static Key obtainKey(String key) {
if (key == null) {
return DEFAULT_KEY;
}
KeyGenerator generator = null;
try {
generator = KeyGenerator.getInstance(DES);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
generator.init(new SecureRandom(key.getBytes()));
Key key1 = generator.generateKey();
generator = null;
return key1;
}
/**
* 加密<br>
* String明文输入,String密文输出
*/
public static String encode(String str) {
return encode64(null, str);
}
/**
* 加密<br>
* String明文输入,String密文输出
*/
public static String encode64(String key, String str) {
return Base64.encodeBase64URLSafeString(obtainEncode(key, str.getBytes()));
}
/**
* 加密<br>
* String明文输入,String密文输出
*/
public static String encode32(String key, String str) {
return base32.encodeAsString(obtainEncode(key, str.getBytes())).replaceAll("=", "");
}
/**
* 加密<br>
* String明文输入,String密文输出
*/
public static String encode16(String key, String str) {
return Hex.encodeHexString(obtainEncode(key, str.getBytes()));
}
/**
* 解密<br>
* 以String密文输入,String明文输出
*/
public static String decode(String str) {
return decode64(null, str);
}
/**
* 解密<br>
* 以String密文输入,String明文输出
*/
public static String decode64(String key, String str) {
return new String(obtainDecode(key, Base64.decodeBase64(str)));
}
/**
* 解密<br>
* 以String密文输入,String明文输出
*/
public static String decode32(String key, String str) {
return new String(obtainDecode(key, base32.decode(str)));
}
/**
* 解密<br>
* 以String密文输入,String明文输出
*/
public static String decode16(String key, String str) {
try {
return new String(obtainDecode(key, Hex.decodeHex(str.toCharArray())));
} catch (DecoderException e) {
e.printStackTrace();
}
return null;
}
/**
* 加密<br>
* 以byte[]明文输入,byte[]密文输出
*/
private static byte[] obtainEncode(String key, byte[] str) {
byte[] byteFina = null;
Cipher cipher;
try {
Key key1 = obtainKey(key);
cipher = Cipher.getInstance(DES);
cipher.init(Cipher.ENCRYPT_MODE, key1);
byteFina = cipher.doFinal(str);
} catch (Exception e) {
e.printStackTrace();
} finally {
cipher = null;
}
return byteFina;
}
/**
* 解密<br>
* 以byte[]密文输入,以byte[]明文输出
*/
private static byte[] obtainDecode(String key, byte[] str) {
Cipher cipher;
byte[] byteFina = null;
try {
Key key1 = obtainKey(key);
cipher = Cipher.getInstance(DES);
cipher.init(Cipher.DECRYPT_MODE, key1);
byteFina = cipher.doFinal(str);
} catch (Exception e) {
e.printStackTrace();
} finally {
cipher = null;
}
return byteFina;
}
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long time = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
System.out.println("");
time += i * 10000;
Date date = new Date(time);
String a = sdf.format(date);;
String key = "100000031553";
System.out.println(a);
String m = encode64(DEFAULT_SECRET_KEY2 + key, a);
String m3 = key + ";" + m;
System.out.println(m3);
String m2 = encode32(DEFAULT_SECRET_KEY3, m3);
System.out.println(m2);
String n1 = decode32(DEFAULT_SECRET_KEY3, m2);
System.out.println(n1);
String key1 = n1.split(";")[0];
String m4 = n1.split(";")[1];
String n = decode64(DEFAULT_SECRET_KEY2 + key1, m4);
System.out.println(n);
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
结果
2017-06-20 15:30:16
100000031553;7Qk_iXXcFTwH3JmRGkTq4tmq1qGfZNT6
HP5PAULJEMWHYDWZ4H6BS3PCS745X5EG5HWP3BVGZ7ZWKT5K4OXAPVYMHFMSGVIT7Z3NRLARA42Q2
100000031553;7Qk_iXXcFTwH3JmRGkTq4tmq1qGfZNT6
2017-06-20 15:30:16
2017-06-20 15:30:26
100000031553;7Qk_iXXcFTwH3JmRGkTq4s58fRfWxnIB
HP5PAULJEMWHYDWZ4H6BS3PCS745X5EG5HWP3BVGZ7ZWKT5K4OXDYP2MNCOFIXQT64E7VFTSORNDC
100000031553;7Qk_iXXcFTwH3JmRGkTq4s58fRfWxnIB
2017-06-20 15:30:26
2017-06-20 15:30:46
100000031553;7Qk_iXXcFTwH3JmRGkTq4nKWCyGA6Ugc
HP5PAULJEMWHYDWZ4H6BS3PCS745X5EG5HWP3BVGZ7ZWKT5K4OXBQIPHRJV47XVA5FX5VZZBDVWU6
100000031553;7Qk_iXXcFTwH3JmRGkTq4nKWCyGA6Ugc
2017-06-20 15:30:46
2017-06-20 15:31:16
100000031553;7Qk_iXXcFTzyyutOzohMQtmq1qGfZNT6
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYL4IIWJAWBLNWPYSYB27HFVKEOL7Z3NRLARA42Q2
100000031553;7Qk_iXXcFTzyyutOzohMQtmq1qGfZNT6
2017-06-20 15:31:16
2017-06-20 15:31:56
100000031553;7Qk_iXXcFTzyyutOzohMQhL-TRzsQ4wg
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYL4IIWJAWBLNWPXIEYVNCOWZTSUCOQNVVTRFOQ7Q
100000031553;7Qk_iXXcFTzyyutOzohMQhL-TRzsQ4wg
2017-06-20 15:31:56
2017-06-20 15:32:46
100000031553;7Qk_iXXcFTx1gnomCm36IXKWCyGA6Ugc
HP5PAULJEMWHYDWZ4H6BS3PCS44EWYFE3D2ARU6PUUPSHOUUIYRGA57JF7APJOXF5FX5VZZBDVWU6
100000031553;7Qk_iXXcFTx1gnomCm36IXKWCyGA6Ugc
2017-06-20 15:32:46
2017-06-20 15:33:46
100000031553;7Qk_iXXcFTwGH7nHwdqVbHKWCyGA6Ugc
HP5PAULJEMWHYDWZ4H6BS3PCS745X5EG5HWP3BTETSGUKCFFO4KMXWNBDNAVQO4O5FX5VZZBDVWU6
100000031553;7Qk_iXXcFTwGH7nHwdqVbHKWCyGA6Ugc
2017-06-20 15:33:46
2017-06-20 15:34:56
100000031553;7Qk_iXXcFTz7e6yP03d6ShL-TRzsQ4wg
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYNERSSNAVUAXJYT25WYN4R3AKAXCOQNVVTRFOQ7Q
100000031553;7Qk_iXXcFTz7e6yP03d6ShL-TRzsQ4wg
2017-06-20 15:34:56
2017-06-20 15:36:16
100000031553;7Qk_iXXcFTyi3f-tzQIrstmq1qGfZNT6
HP5PAULJEMWHYDWZ4H6BS3PCS7UMVFE4CEGRKAZDC35SYFQFNQRL6BYJNXE6O6AJ7Z3NRLARA42Q2
100000031553;7Qk_iXXcFTyi3f-tzQIrstmq1qGfZNT6
2017-06-20 15:36:16
2017-06-20 15:37:46
100000031553;7Qk_iXXcFTzJprxuUcffn3KWCyGA6Ugc
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYPPVN4Z6AKJFAD6GDEP3CZ7RLG25FX5VZZBDVWU6
100000031553;7Qk_iXXcFTzJprxuUcffn3KWCyGA6Ugc
2017-06-20 15:37:46
2017-06-20 15:39:26
100000031553;7Qk_iXXcFTzSsncbwQVGsM58fRfWxnIB
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYIIBH2OZLX74VCRQYSVL3O4I4H364E7VFTSORNDC
100000031553;7Qk_iXXcFTzSsncbwQVGsM58fRfWxnIB
2017-06-20 15:39:26
2017-06-20 15:41:16
100000031553;7Qk_iXXcFTxMJUI0WN0ZY9mq1qGfZNT6
HP5PAULJEMWHYDWZ4H6BS3PCS44EWYFE3D2ARU4HKMGIF5XDUK3NIR2K35ZINPMA7Z3NRLARA42Q2
100000031553;7Qk_iXXcFTxMJUI0WN0ZY9mq1qGfZNT6
2017-06-20 15:41:16
2017-06-20 15:43:16
100000031553;7Qk_iXXcFTyhH9RtWUFfZdmq1qGfZNT6
HP5PAULJEMWHYDWZ4H6BS3PCS7UMVFE4CEGRKAZYUL43EZUWDOCWT6WYTGHDGQ2S7Z3NRLARA42Q2
100000031553;7Qk_iXXcFTyhH9RtWUFfZdmq1qGfZNT6
2017-06-20 15:43:16
2017-06-20 15:45:26
100000031553;7Qk_iXXcFTwy6gzzKkG_qs58fRfWxnIB
HP5PAULJEMWHYDWZ4H6BS3PCS745X5EG5HWP3BV3WZ3KE372K2U3FGAK57LSO3SU64E7VFTSORNDC
100000031553;7Qk_iXXcFTwy6gzzKkG_qs58fRfWxnIB
2017-06-20 15:45:26
2017-06-20 15:47:46
100000031553;7Qk_iXXcFTz8oyv2bdPXPXKWCyGA6Ugc
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYN4PRUKST62GI6AVEF6E36K6DR55FX5VZZBDVWU6
100000031553;7Qk_iXXcFTz8oyv2bdPXPXKWCyGA6Ugc
2017-06-20 15:47:46
2017-06-20 15:50:16
100000031553;7Qk_iXXcFTzJKoMEaxLG6Nmq1qGfZNT6
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYOYM7RYDGNQJJZNRR7GGEOCJRXA7Z3NRLARA42Q2
100000031553;7Qk_iXXcFTzJKoMEaxLG6Nmq1qGfZNT6
2017-06-20 15:50:16
2017-06-20 15:52:56
100000031553;7Qk_iXXcFTwgU0HaxMe9nxL-TRzsQ4wg
HP5PAULJEMWHYDWZ4H6BS3PCS745X5EG5HWP3BS4UHZBYN7ZDDP7NNCKZSOPUSSQCOQNVVTRFOQ7Q
100000031553;7Qk_iXXcFTwgU0HaxMe9nxL-TRzsQ4wg
2017-06-20 15:52:56
2017-06-20 15:55:46
100000031553;7Qk_iXXcFTymybkBj5lr7HKWCyGA6Ugc
HP5PAULJEMWHYDWZ4H6BS3PCS7UMVFE4CEGRKA2HP5WAIOMKP3FHT6RN4FDZRLPQ5FX5VZZBDVWU6
100000031553;7Qk_iXXcFTymybkBj5lr7HKWCyGA6Ugc
2017-06-20 15:55:46
2017-06-20 15:58:46
100000031553;7Qk_iXXcFTxhdbGyk0KuLHKWCyGA6Ugc
HP5PAULJEMWHYDWZ4H6BS3PCS44EWYFE3D2ARUYMKPKQYKCYZ2GMWUPHY5VD3OSH5FX5VZZBDVWU6
100000031553;7Qk_iXXcFTxhdbGyk0KuLHKWCyGA6Ugc
2017-06-20 15:58:46
2017-06-20 16:01:56
100000031553;7Qk_iXXcFTxuql1HgYDmyhL-TRzsQ4wg
HP5PAULJEMWHYDWZ4H6BS3PCS44EWYFE3D2ARU3HKRH5CDQCNEM4CZ27FXRULI4ACOQNVVTRFOQ7Q
100000031553;7Qk_iXXcFTxuql1HgYDmyhL-TRzsQ4wg
2017-06-20 16:01:56
2017-06-20 16:05:16
100000031553;7Qk_iXXcFTz4lr0p_jSU-9mq1qGfZNT6
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYMO3VHNQRMJTBJPLOQKF3GTRURX7Z3NRLARA42Q2
100000031553;7Qk_iXXcFTz4lr0p_jSU-9mq1qGfZNT6
2017-06-20 16:05:16
2017-06-20 16:08:46
100000031553;7Qk_iXXcFTw2LMEDaOzVMnKWCyGA6Ugc
HP5PAULJEMWHYDWZ4H6BS3PCS745X5EG5HWP3BVC7XI4CVDE7FKZIBR3NUSI3ACQ5FX5VZZBDVWU6
100000031553;7Qk_iXXcFTw2LMEDaOzVMnKWCyGA6Ugc
2017-06-20 16:08:46
2017-06-20 16:12:26
100000031553;7Qk_iXXcFTzFuWwO_Bijuc58fRfWxnIB
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYJIACH65DE2GEV25WML7I3KBNUM64E7VFTSORNDC
100000031553;7Qk_iXXcFTzFuWwO_Bijuc58fRfWxnIB
2017-06-20 16:12:26
2017-06-20 16:16:16
100000031553;7Qk_iXXcFTzHsITEL62matmq1qGfZNT6
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYNILYXRHAEA2UTJSEO3DXMMGM2Z7Z3NRLARA42Q2
100000031553;7Qk_iXXcFTzHsITEL62matmq1qGfZNT6
2017-06-20 16:16:16
2017-06-20 16:20:16
100000031553;7Qk_iXXcFTz9PnxNxOj8D9mq1qGfZNT6
HP5PAULJEMWHYDWZ4H6BS3PCS4SCB2IZ6OPGDYKDWI7MGJXV5XGCZRQT5NDYKFQG7Z3NRLARA42Q2
100000031553;7Qk_iXXcFTz9PnxNxOj8D9mq1qGfZNT6
2017-06-20 16:20:16
2017-06-20 16:24:26
100000031553;7Qk_iXXcFTxJ1FcTv0Lifs58fRfWxnIB
HP5PAULJEMWHYDWZ4H6BS3PCS44EWYFE3D2ARUY2GCF3PSLWH6UVK4YGMLKD7CQW64E7VFTSORNDC
100000031553;7Qk_iXXcFTxJ1FcTv0Lifs58fRfWxnIB
2017-06-20 16:24:26
2017-06-20 16:28:46
100000031553;7Qk_iXXcFTydP4gY2EfCZ3KWCyGA6Ugc
HP5PAULJEMWHYDWZ4H6BS3PCS7UMVFE4CEGRKAYA7DGV33ZKTXXKQMY22GM2LWRT5FX5VZZBDVWU6
100000031553;7Qk_iXXcFTydP4gY2EfCZ3KWCyGA6Ugc
2017-06-20 16:28:46
2017-06-20 16:33:16
100000031553;7