|
@@ -156,29 +156,29 @@ public abstract class DESCoder extends Coder{
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void main(String[] args) throws Exception{
|
|
|
- String phone="18683951945";
|
|
|
- final String key="sajsajsajdjsdsaj";
|
|
|
- byte[] keyBytes= Base64.encodeBase64String(key.getBytes("UTF8")).getBytes();
|
|
|
-
|
|
|
- DESKeySpec dks = new DESKeySpec(keyBytes);
|
|
|
- SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
|
|
|
- SecretKey secretKey = keyFactory.generateSecret(dks);
|
|
|
-
|
|
|
- //加密
|
|
|
- Cipher cipherEncode = Cipher.getInstance("DES");
|
|
|
- cipherEncode.init(Cipher.ENCRYPT_MODE, secretKey);
|
|
|
- byte[] desEncodebytes = cipherEncode.doFinal(phone.getBytes("UTF8"));
|
|
|
- String desEncode =Base64.encodeBase64URLSafeString(desEncodebytes);
|
|
|
- System.out.println(desEncode);
|
|
|
-
|
|
|
- //解密
|
|
|
- Cipher cipherDecode = Cipher.getInstance("DES");
|
|
|
- cipherDecode.init(Cipher.DECRYPT_MODE, secretKey);
|
|
|
- byte[] desEncodebyte = Base64.decodeBase64(desEncode);
|
|
|
- byte[] desDecodebytes= cipherDecode.doFinal(desEncodebyte);
|
|
|
- String desDecode =new String(desDecodebytes,"UTF8");
|
|
|
- System.out.println(desDecode);
|
|
|
-
|
|
|
- }
|
|
|
+// public static void main(String[] args) throws Exception{
|
|
|
+// String phone="18683951945";
|
|
|
+// final String key="sajsajsajdjsdsaj";
|
|
|
+// byte[] keyBytes= Base64.encodeBase64String(key.getBytes("UTF8")).getBytes();
|
|
|
+//
|
|
|
+// DESKeySpec dks = new DESKeySpec(keyBytes);
|
|
|
+// SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
|
|
|
+// SecretKey secretKey = keyFactory.generateSecret(dks);
|
|
|
+//
|
|
|
+// //加密
|
|
|
+// Cipher cipherEncode = Cipher.getInstance("DES");
|
|
|
+// cipherEncode.init(Cipher.ENCRYPT_MODE, secretKey);
|
|
|
+// byte[] desEncodebytes = cipherEncode.doFinal(phone.getBytes("UTF8"));
|
|
|
+// String desEncode =Base64.encodeBase64URLSafeString(desEncodebytes);
|
|
|
+// System.out.println(desEncode);
|
|
|
+//
|
|
|
+// //解密
|
|
|
+// Cipher cipherDecode = Cipher.getInstance("DES");
|
|
|
+// cipherDecode.init(Cipher.DECRYPT_MODE, secretKey);
|
|
|
+// byte[] desEncodebyte = Base64.decodeBase64(desEncode);
|
|
|
+// byte[] desDecodebytes= cipherDecode.doFinal(desEncodebyte);
|
|
|
+// String desDecode =new String(desDecodebytes,"UTF8");
|
|
|
+// System.out.println(desDecode);
|
|
|
+//
|
|
|
+// }
|
|
|
}
|