?? custencyauti.java
字號:
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.net.*;
public class CustEncyAuti {
//定義 加密算法,可用 DES,DESede,Blowfish
private static String Algorithm="DES";
public CustEncyAuti(){}
public static byte[] encryp(byte[] keybyte, byte[] src)
{
try
{
//生成密鑰
SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
//加密
Cipher c1 = Cipher.getInstance(Algorithm);
c1.init(Cipher.ENCRYPT_MODE, deskey);
return c1.doFinal(src);
}
catch(Exception e){e.printStackTrace();}
return null;
}
public static void main(String[] args) throws Exception
{
// TODO: Add your code here
Security.addProvider(new com.sun.crypto.provider.SunJCE());
final byte[] keyBytes = {0x11, 0x22, 0x4F, 0x58, (byte)0x88, 0x10, 0x40, 0x38
, 0x28, 0x25, 0x79, 0x51, (byte)0xCB, (byte)0xDD, 0x55, 0x66
, 0x77, 0x29, 0x74, (byte)0x98, 0x30, 0x40, 0x36, (byte)0xE2}; //24字節的密鑰
String szSrc = "This is a test!";
System.out.println("加密前的字符串:" + szSrc);
byte[] encoded = encryp(keyBytes, szSrc.getBytes());
System.out.println("加密后的字符串:" + new String(encoded));
DatagramSocket ds=new DatagramSocket();
DatagramPacket dp=new DatagramPacket(encoded,encoded.length,
InetAddress.getByName("127.0.0.1"),3000);
ds.send(dp);
ds.close();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -