当前位置:网站首页>Experimental report on information management and information system [information security and confidentiality] of Huazhong Agricultural University
Experimental report on information management and information system [information security and confidentiality] of Huazhong Agricultural University
2022-06-11 05:47:00 【swindler.】
Information security and confidentiality test report
1. The experiment purpose
This experiment uses Xcode As a development tool ,swift As the main development language , Simply write the application page , It presents the encryption and decryption in the course of information security and decryption , Combine theory with practice to consolidate and strengthen the absorption and application of knowledge . The algorithm implementation part mainly uses AES Algorithm for encryption and decryption , Use MD5 Abstract algorithm for encryption .
2. Experimental process
2.1 Build a page
The main page elements are as follows :
class ViewController: UIViewController,UITextFieldDelegate {
var flag = false
var label1:UILabel!
var label2:UILabel!
var output1:String! = ""
var output2:String! = ""
var result:UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let screen = UIScreen.main.bounds
self.view.backgroundColor = .systemYellow
// Add tags
let labelHeight:CGFloat = 100
let labelWidth:CGFloat = 100
let labelTopView:CGFloat = 100
self.label1 = UILabel(frame: CGRect(x:(screen.size.width - labelWidth)/2 , y: labelTopView, width: labelWidth, height: labelHeight))
self.label1.text = " Plaintext :"
self.label1.font = .boldSystemFont(ofSize: 22)
self.label1.textColor = .systemBlue
self.label1.textAlignment = .center
self.view.addSubview(self.label1)
// add to textField
let textFieldHeight:CGFloat = 50
let textFieldWidth:CGFloat = 300
let textFieldTopView:CGFloat = 200
let textField = UITextField(frame: CGRect(x: (screen.size.width - textFieldWidth)/2, y: textFieldTopView, width: textFieldWidth, height: textFieldHeight))
textField.placeholder = " Please enter relevant information "
textField.borderStyle = .roundedRect
textField.clearButtonMode = .whileEditing
textField.becomeFirstResponder()
textField.returnKeyType = .done
textField.textColor = .systemBlue
textField.allowsEditingTextAttributes = .random()
textField.delegate = self
self.view.addSubview(textField)
// Add a button
let button = UIButton(type: .custom)
let buttonHeight:CGFloat = 60
let buttonWidth:CGFloat = 100
let buttonTopView:CGFloat = 650
let frame = CGRect(x: (screen.size.width - buttonWidth)/2, y: buttonTopView, width: buttonWidth, height: buttonHeight)
button.frame = frame
button.backgroundColor = .red
button.layer.cornerRadius = 6
button.layer.borderColor = UIColor.red.cgColor
button.layer.borderWidth = 1
button.setTitle(" encryption ", for: UIControl.State())
button.titleLabel?.font = .boldSystemFont(ofSize: 17)
button.addTarget(self, action: #selector(modeChanged(_:)), for: .touchUpInside)
self.view.addSubview(button)
// Add a result callout :
self.label2 = UILabel(frame: CGRect(x: (screen.size.width - labelWidth)/2, y: 270, width: labelWidth, height: labelHeight))
self.label2.text = " Ciphertext :"
self.label2.font = .boldSystemFont(ofSize: 22)
self.label2.textAlignment = .center
self.label2.textColor = .systemBlue
self.view.addSubview(self.label2)
// Add result labels
let resultHeight:CGFloat = 100
let resultWidth:CGFloat = 300
let resultTopView:CGFloat = 370
self.result = UILabel(frame: CGRect(x: (screen.size.width - resultWidth)/2, y: resultTopView, width: resultWidth, height: resultHeight))
self.result.text = ""
self.result.font = .boldSystemFont(ofSize: 22)
self.result.textColor = .systemBlue
self.result.textAlignment = .center
self.result.lineBreakMode = NSLineBreakMode.byWordWrapping
self.result.numberOfLines = 0
self.result.layer.cornerRadius = 5
self.result.layer.masksToBounds = true
self.result.layer.borderWidth = 1
self.result.layer.borderColor = .init(red: 1, green: 1, blue: 1, alpha: 1)
self.result.layer.backgroundColor = .init(red: 1, green: 1, blue: 1, alpha: 1)
self.view.addSubview(result)
// Add toggle button
let toggleHeight:CGFloat = 40
let togggleWidth:CGFloat = 50
let toggleTopView:CGFloat = 550
let toggleButton = UIButton(frame: CGRect(x: (screen.size.width - togggleWidth)/2, y: toggleTopView, width: togggleWidth, height: toggleHeight))
toggleButton.backgroundColor = .gray
toggleButton.layer.borderColor = UIColor.gray.cgColor
toggleButton.layer.borderWidth = 1
toggleButton.layer.cornerRadius = 6
toggleButton.setTitle(" Switch ", for: UIControl.State())
toggleButton.titleLabel?.font = .boldSystemFont(ofSize: 13)
toggleButton.addTarget(self, action: #selector(toggle(_:)), for: .touchUpInside)
self.view.addSubview(toggleButton)
2.2 Algorithm implementation
2.2.1 MD5 Implementation of algorithm encryption
1. stay Teminal The terminal uses the command line to create a Podfile
$ touch Podfile
$ open -e Podfile
2. In the just popped Podfile Add the following to the file
pod ‘CryptoSwift’
3. After downloading the third-party library successfully , Can be in Viewcontroller.swift The first line of the file introduces
import CryptoSwift
because Swift Third party library CryptoSwift yes Swift A collection of standards and secure encryption algorithms implemented in , therefore md5 The implementation of the algorithm can directly call the md5() The method can
The function code of the algorithm embedded page is as follows :
@objc func modeChanged(_ sender:AnyObject){
self.result.text = output1
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
output1 = textField.text?.md5()
//output2 = textField.text.
return true
}
2.2.2 AES Implementation of algorithm encryption and decryption
encryption
func Encode_AES_ECB(strToEncode:String)->String {
var encodeString = ""
do {
let aes = try AES(key: Padding.zeroPadding.add(to: key.bytes, blockSize: AES.blockSize), blockMode: ECB(),padding: .pkcs7)
let encoded = try aes.encrypt(strToEncode.bytes)
encodeString = encoded.toBase64()
print(encodeString)
}catch{
print(error.localizedDescription)
}
return encodeString
}
Decrypt
func Decode_AES_ECB(strToDecode:String)->String {
var decodeString = ""
let data = NSData(base64Encoded: strToDecode, options: NSData.Base64DecodingOptions.init(rawValue: 0))
var encrypted:[UInt8] = []
let count = data?.length
for i in 0..<count!{
var temp:UInt8 = 0
data?.getBytes(&temp, range: NSRange(location: i, length: 1))
encrypted.append(temp)
}
do {
let aes = try AES(key: Padding.zeroPadding.add(to: key.bytes, blockSize: AES.blockSize), blockMode: ECB(), padding: .pkcs7)
let decode = try aes.decrypt(encrypted)
let encoded = Data(decode)
decodeString = String(bytes: encoded.bytes, encoding: .utf8)!
}catch{
print(error.localizedDescription)
}
return decodeString
}
The function code of the algorithm embedded function page is as follows :
@objc func modeChanged(_ sender:AnyObject){
if self.label1.text == " Plaintext :" {
result.text = Encode_AES_ECB(strToEncode: output1)
}else if self.label1.text == " Ciphertext :" {
result.text = Decode_AES_ECB(strToDecode: output1)
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
output1 = textField.text
return true
}
@objc func toggle(_ sender:AnyObject){
if flag {
self.label1.text = " Ciphertext :"
self.label2.text = " Plaintext :"
self.button.setTitle(" Decrypt ", for: UIControl.State())
self.result.text = ""
flag = false
}else{
self.label1.text = " Plaintext :"
self.label2.text = " Ciphertext :"
self.button.setTitle(" encryption ", for: UIControl.State())
self.result.text = ""
flag = true
}
}
2.3 Results display
- The page display :

- md5 Abstract algorithm :


- AES Algorithm :
encryption :
Switch :
Decrypt :
Experimental experience
Through this experiment , My harvest is as follows :
- take “ Information security and confidentiality ” This course combines theory and practice more closely . It's on paper , Only listening to the teacher talk about abstract theoretical knowledge in the classroom makes me not fully understand this course , The experiment makes the teacher's pages PPT Become lines of code that can be implemented and manipulated , Enhanced sense of achievement in learning , When doing experiments , In my mind, I recall the relevant knowledge that the teacher talked about in class , The mastery and understanding of corresponding courses have been deepened !
- Enhanced the improvement of personal skill level . Self taught mobile terminal for nearly half a year iOS Development , But never put the new knowledge outside the classroom into the classroom of their own experience . This experiment gave me a good chance , Not just the implementation of the algorithm , The construction of web page , The composition of the elements , The processing logic between various elements and events also makes me ponder , Racking my brains . In the end, Kung Fu is not inferior to those who want it , The whole application runs smoothly !
- Great improvement of learning ability . Due to the use of iOS Medium swift Language experiment , So most of the information on the Internet can not be used directly , thus , Force yourself to study carefully CryptoSwift The source code of the library and the old version on the network Xcode Version encryption algorithm is summarized , Finally, it is suitable for Xcode11, as well as iOS10 The encryption and decryption algorithm and its function realization on the above simulator .
- Last , Thank Mr. Zhang and the students for their encouragement and patient help !
边栏推荐
- Flask develops and implements the like comment module of the online question and answer system
- 使用Batch设置IP地址
- What is a thread pool?
- MySQL circulates multiple values foreach, XML writing method
- Why is the smart door lock so popular? What about the smart door locks of MI family and zhiting?
- NDK learning notes (VI) Basics: memory management, standard file i/o
- YOLOv5的Tricks | 【Trick8】图片采样策略——按数据集各类别权重采样
- Get the value of program exit
- SQLite installation and configuration tutorial +navicat operation
- Using batch enumeration files
猜你喜欢

Basics of customized view

Use com youth. banner. Solution to the inflateexception reported by the banner plug-in

String sorting times --- bubble sorting deformation

Bert knowledge distillation

es-ik 安装报错

NDK learning notes (VII) system configuration, users and groups

NDK learning notes (XI) POSIX sockect local communication

Cocoapods installation error

20多种云协作功能,3分钟聊透企业的数据安全经

Stone game -- leetcode practice
随机推荐
Wechat applet learning record
Redis setup (sentinel mode)
49. grouping of acronyms
NFC Development -- difference between ID card and IC card (M1 card and CPU card) (III)
Wxparse parsing iframe playing video
How to make lamps intelligent? How to choose single fire and zero fire intelligent switches!
Further efficient identification of memory leakage based on memory optimization tool leakcanary and bytecode instrumentation technology
Concepts and differences of parallel computing, distributed computing and cluster (to be updated for beginners)
Maximum number of points on the line ----- hash table solution
What is a thread pool?
Cocoapods installation error
微信自定义组件---样式--插槽
AttributeError: ‘HistGradientBoostingClassifier‘ object has no attribute ‘_ n_ features‘
Recherche sur l'optimisation de Spark SQL basée sur CBO pour kangourou Cloud Stack
Deep learning distributed training
getBackgroundAudioManager控制音乐播放(类名的动态绑定)
Multithreading tutorial (XXVI) field updater and atomic accumulator
Customize the layout of view Foundation
深度学习分布式训练
When the recyclerview plays more videos, the problem of refreshing the current video is solved.