当前位置:网站首页>Information Security Experiment 1: implementation of DES encryption algorithm
Information Security Experiment 1: implementation of DES encryption algorithm
2022-07-07 09:22:00 【Not enough to eat】
One 、 Purpose and requirements of the experiment
1. Familiar with encryption 、 Decryption algorithm ; Understand the important role of encryption in communication ;
2. Encrypt the entered hexadecimal number ( Convert the input characters into integers ), Compare input and output , When changing the input number by one bit , Compare changes in output , Explain why .
3. Realize the encryption and decryption of a file , Submit program code and execution results .
Two 、 Experimental content
This experiment uses DES The algorithm encrypts and decrypts the actual data to gain a deep understanding DES Operating principle . Analyze according to the program provided DES The realization process of the algorithm . In analyzing the key generation function 、 Encryption function (8 byte )、 Decryption function 、 Test function and key length test function , use C/VC++ or Java Language programming to encrypt and decrypt text files .
3、 ... and 、 Experimental environment
function windows or Linux Operating system PC machine , have VC(windows)、gcc(Linux) etc. C Language compilation environment or Java Environmental Science .
Four 、 Experimental steps and result analysis
- Running results
1.1、 The original document

Encrypted file

Decrypted file

- Code
public class TestDES {
Key key;
public TestDES(String str) {
getKey(str);// Generate key
}
// Generate... Based on parameters KEY
public void getKey(String strKey) {
try {
KeyGenerator _generator = KeyGenerator.getInstance("DES");
_generator.init(new SecureRandom(strKey.getBytes()));
this.key = _generator.generateKey();
_generator = null;
}
catch (Exception e) {
throw new RuntimeException("Error initializing SqlMap class. Cause: " + e);
}
}
public void encrypt(String file, String destFile) throws Exception {
Cipher cipher = Cipher.getInstance("DES");
// cipher.init(Cipher.ENCRYPT_MODE, getKey());
cipher.init(Cipher.ENCRYPT_MODE, this.key);
InputStream is = new FileInputStream(file);
OutputStream out = new FileOutputStream(destFile);
CipherInputStream cis = new CipherInputStream(is, cipher);
byte[] buffer = new byte[1024];
int r;
while ((r = cis.read(buffer)) > 0) {
out.write(buffer, 0, r);
}
cis.close();
is.close();
out.close();
}
public void decrypt(String file, String dest) throws Exception {
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, this.key);
InputStream is = new FileInputStream(file);
OutputStream out = new FileOutputStream(dest);
CipherOutputStream cos = new CipherOutputStream(out, cipher);
byte[] buffer = new byte[1024];
int r;
while ((r = is.read(buffer)) >= 0) {
cos.write(buffer, 0, r);
}
cos.close();
out.close();
is.close();
}
public static void main(String[] args) throws Exception {
TestDES td = new TestDES("24234");
td.encrypt("D:/Desktop/test.txt", "D:/Desktop/test1.txt"); // encryption
td.decrypt("D:/Desktop/test1.txt", "D:/Desktop/test2.txt"); // Decrypt
}
}
边栏推荐
- Kubernetes cluster capacity expansion to add node nodes
- Postman interface debugging method
- Pytest+request+allure+excel interface automatic construction from 0 to 1 [five nails / flying Book notice]
- Postman interface test (I. installation and use)
- 信息安全实验三 :PGP邮件加密软件的使用
- Regularly modify the system time of the computer
- PMP Exam Preparation experience systematically improve project management knowledge through learning
- Error: selenium common. exceptions. WebDriverException: Messag‘geckodriver‘ execute
- Systick tick timer
- Unity shader (to achieve a simple material effect with adjustable color attributes only)
猜你喜欢

Regular matching starts with XXX and ends with XXX

Mysql:select ... for update

C language pointer (Part 2)

Locust performance test 2 (interface request)

超十万字_超详细SSM整合实践_手动实现权限管理

Connecting mobile phone with ADB

信息安全实验三 :PGP邮件加密软件的使用

Sublime Text4 download the view in bower and set the shortcut key

Do you have any certificates with high gold content?

What is MD5
随机推荐
Interface test API case, data and interface separation
Record of structured interview
5A summary: seven stages of PMP learning
Jenkins automated email
Kubernetes cluster capacity expansion to add node nodes
Using JWT to realize login function
Do you have any certificates with high gold content?
[chaosblade: delete pod according to the tag, pod domain name access exception scenario, pod file system i/o failure scenario]
四、机器学习基础
NVIC中断优先级管理
Leetcode question brushing record (array) combination sum, combination sum II
How to use Arthas to view class variable values
浏览器中如何让视频倍速播放
The configuration and options of save actions are explained in detail, and you won't be confused after reading it
PMP Exam details after the release of the new exam outline
STM32的时钟系统
MySql数据库-索引-学习笔记
The essence of high availability
C语言指针(上篇)
答案在哪里?action config/Interceptor/class/servlet