当前位置:网站首页>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
}
}
边栏推荐
- Confitest of fixture py
- 答案在哪里?action config/Interceptor/class/servlet
- STM32 serial port register library function configuration method
- Record of structured interview
- Jenkins task grouping
- Detailed learning notes of JVM memory structure (I)
- Summary of PMP learning materials
- Test Engineer Interview Questions 2022
- E-commerce campaign Guide
- Jemter operation
猜你喜欢
![[istio introduction, architecture, components]](/img/2b/f84e5cdac6ed9b429e053ffc8dbeb0.png)
[istio introduction, architecture, components]

Difference between interface iterator and iteratable

Postman data driven

E-commerce campaign Guide

STM32 serial port register library function configuration method

Several stages of PMP preparation study

Connecting mobile phone with ADB

PMP Exam Preparation experience systematically improve project management knowledge through learning

Install pyqt5 and Matplotlib module

Mysql database transaction learning notes
随机推荐
Error: selenium common. exceptions. WebDriverException: Messag‘geckodriver‘ execute
Interview question: general layout and wiring principles of high-speed PCB
Unittest simple project
Integer or int? How to select data types for entity classes in ORM
Where is the answer? action config/Interceptor/class/servlet
信息安全实验二 :使用X-SCANNER扫描工具
External interrupt to realize key experiment
The essence of high availability
SiteMesh getting started example
What is the use of PMP certificate?
PMP experience learning and sharing process
Leetcode question brushing record (array) combination sum, combination sum II
网易云微信小程序
E-commerce campaign Guide
Locust performance test 4 (custom load Policy)
stm32和电机开发(从单机版到网络化)
Reflections on the way of enterprise IT architecture transformation (Alibaba's China Taiwan strategic thought and architecture practice)
MySQL common statements
Zen - batch import test cases
Systick滴答定时器