密码常用术语
- 明文:待加密信息
- 密文:经过加密后的明文
- 加密:明文转为密文
- 加密算法:明文转为密文的转换算法
- 加密秘钥:通过加密算法进行加密操作用的秘钥
- 解密算法:将密文转换为明文的算法
- 解密秘钥:通过加密算法进行解密操作的秘钥
- 主动攻击:攻击者非法侵入密码系统,对系统注入假消息进行欺骗
- 科克霍夫:系统的安全基于秘钥,即对算法公开,对秘钥保密
密码分类
按时间分
- 古典密码:以字符为基本加密单元
- 现代密码:以信息块为基本加密单元
按保密内容划分
- 受限制算法:算法保密性基于保持算法的秘密(古典密码)
- 基于秘钥的算法:基于科克霍夫原则(现代密码)
按照密码体制
- 对称密码:加密与加密秘钥相同
- 非对称密码:加解密秘钥不同
OSI与TCP/IP安全体系
JAVA安全组成
实现Base64算法
import java.io.IOException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class Base64 {
private static String str = "security base64";
public static void main(String[] args) {
jdkBase64();
commonsCodesBase64();
bouncyCastleBase64();
}
public static void jdkBase64() {
try {
BASE64Encoder encoder = new BASE64Encoder();
String encode = encoder.encode(str.getBytes());
System.out.println("encode:" + encode);
BASE64Decoder decoder = new BASE64Decoder();
System.out.println("decode:" + new String(decoder.decodeBuffer(encode)));
} catch (IOException e) {
e.printStackTrace();
}
}
public static void commonsCodesBase64() {
byte[] encodeByte = org.apache.commons.codec.binary.Base64.encodeBase64(str.getBytes());
System.out.println("encode:" + new String(encodeByte));
byte[] decodeByte = org.apache.commons.codec.binary.Base64.decodeBase64(encodeByte);
System.out.println("decode:" + new String(decodeByte));
}
public static void bouncyCastleBase64() {
byte[] encodeByte = org.bouncycastle.util.encoders.Base64.encode(str.getBytes());
System.out.println("encode:" + new String(encodeByte));
byte[] decodeByte = org.bouncycastle.util.encoders.Base64.decode(encodeByte);
System.out.println("decode:" + new String(decodeByte));
}
}
Base64算法应用场景