Skip to content

Commit 1ead1bf

Browse files
committed
init
1 parent 0afe016 commit 1ead1bf

File tree

241 files changed

+5129
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+5129
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.class
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import javax.crypto.Cipher;
2+
import javax.crypto.KeyGenerator;
3+
import javax.crypto.SecretKey;
4+
5+
public class DESEncrypt {
6+
public static void main(String args[])
7+
{
8+
String codeStringBegin="Sunny Liu"; //要加密的明文
9+
String codeStringEnd=null; //加密后的密文
10+
String decodeString=null; //密文解密后得到的明文
11+
String cipherType = "DESede"; //加密算法类型,可设置为DES、DESede、AES等字符串
12+
int keyLength = 112; //设置密钥长度
13+
try
14+
{
15+
//获取密钥生成器
16+
KeyGenerator keyGen=KeyGenerator.getInstance(cipherType);
17+
//初始化密钥生成器,不同的加密算法其密钥长度可能不同
18+
keyGen.init(keyLength);
19+
//生成密钥
20+
SecretKey key=keyGen.generateKey();
21+
22+
//得到密钥字节码
23+
byte[] keyByte=key.getEncoded();
24+
//输出密钥的字节码
25+
System.out.println("密钥是:");
26+
for(int i=0;i<keyByte.length;i++)
27+
{
28+
System.out.print(keyByte[i]+",");
29+
}
30+
System.out.println("");
31+
//创建密码器
32+
Cipher cp=Cipher.getInstance(cipherType);
33+
//初始化密码器
34+
cp.init(Cipher.ENCRYPT_MODE,key);
35+
System.out.println("要加密的字符串是:"+ codeStringBegin);
36+
byte[] codeStringByte=codeStringBegin.getBytes("UTF8");
37+
System.out.println("要加密的字符串对应的字节码是:");
38+
for(int i=0;i<codeStringByte.length;i++)
39+
{
40+
System.out.print(codeStringByte[i]+",");
41+
}
42+
System.out.println("");
43+
//开始加密
44+
byte[] codeStringByteEnd=cp.doFinal(codeStringByte);
45+
System.out.println("加密后的字符串对应的字节码是:");
46+
for(int i=0;i<codeStringByteEnd.length;i++)
47+
{
48+
System.out.print(codeStringByteEnd[i]+",");
49+
}
50+
System.out.println("");
51+
codeStringEnd=new String(codeStringByteEnd);
52+
System.out.println("加密后的字符串是:" + codeStringEnd);
53+
System.out.println("");
54+
//重新初始化密码器
55+
cp.init(Cipher.DECRYPT_MODE,key);
56+
//开始解密
57+
byte[] decodeStringByteEnd=cp.doFinal(codeStringByteEnd);
58+
System.out.println("解密后的字符串对应的字节码是:");
59+
for(int i=0;i<decodeStringByteEnd.length;i++)
60+
{
61+
System.out.print(decodeStringByteEnd[i]+",");
62+
}
63+
System.out.println("");
64+
decodeString=new String(decodeStringByteEnd);
65+
System.out.println("解密后的字符串是:" + decodeString);
66+
System.out.println("");
67+
}
68+
catch(Exception e)
69+
{
70+
e.printStackTrace();
71+
}
72+
}
73+
}
74+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Client
2+
{
3+
public static void main(String args[])
4+
{
5+
try
6+
{
7+
TV tv;
8+
String brandName=XMLUtilTV.getBrandName();
9+
tv=TVFactory.produceTV(brandName);
10+
tv.play();
11+
}
12+
catch(Exception e)
13+
{
14+
System.out.println(e.getMessage());
15+
}
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class HaierTV implements TV
2+
{
3+
public void play()
4+
{
5+
System.out.println("º£¶ûµçÊÓ»ú²¥·ÅÖÐ......");
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class HisenseTV implements TV
2+
{
3+
public void play()
4+
{
5+
System.out.println("º£ÐŵçÊÓ»ú²¥·ÅÖÐ......");
6+
}
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public interface TV
2+
{
3+
public void play();
4+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class TVFactory
2+
{
3+
public static TV produceTV(String brand) throws Exception
4+
{
5+
if(brand.equalsIgnoreCase("Haier"))
6+
{
7+
System.out.println("电视机工厂生产海尔电视机!");
8+
return new HaierTV();
9+
}
10+
else if(brand.equalsIgnoreCase("Hisense"))
11+
{
12+
System.out.println("电视机工厂生产海信电视机!");
13+
return new HisenseTV();
14+
}
15+
else
16+
{
17+
throw new Exception("对不起,暂不能生产该品牌电视机!");
18+
}
19+
}
20+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import javax.xml.parsers.*;
2+
import org.w3c.dom.*;
3+
import org.xml.sax.SAXException;
4+
import java.io.*;
5+
public class XMLUtilTV
6+
{
7+
//该方法用于从XML配置文件中提取品牌名称,并返回该品牌名称
8+
public static String getBrandName()
9+
{
10+
try
11+
{
12+
//创建文档对象
13+
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
14+
DocumentBuilder builder = dFactory.newDocumentBuilder();
15+
Document doc;
16+
doc = builder.parse(new File("configTV.xml"));
17+
18+
//获取包含品牌名称的文本节点
19+
NodeList nl = doc.getElementsByTagName("brandName");
20+
Node classNode=nl.item(0).getFirstChild();
21+
String brandName=classNode.getNodeValue().trim();
22+
return brandName;
23+
}
24+
catch(Exception e)
25+
{
26+
e.printStackTrace();
27+
return null;
28+
}
29+
}
30+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<brandName>TCL</brandName>
4+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Administrator extends User
2+
{
3+
public Administrator()
4+
{
5+
System.out.println("创建管理员对象!");
6+
}
7+
8+
public void diffOperation()
9+
{
10+
System.out.println("管理员拥有创建和管理假条权限!");
11+
}
12+
}

0 commit comments

Comments
 (0)