@@ -3,51 +3,18 @@ package main
33import (
44 "crypto/aes"
55 "crypto/des"
6- "crypto/md5"
7- "crypto/rc4"
8- "crypto/sha1"
9- "crypto/sha256"
106)
117
12- func main () {
13- public := []byte ("hello" )
14-
15- password := []byte ("123456" )
16- buf := password // testing dataflow by passing into different variable
17-
18- // BAD, des is a weak crypto algorithm and password is sensitive data
19- des .NewTripleDESCipher (buf )
20-
21- // BAD, md5 is a weak crypto algorithm and password is sensitive data
22- md5 .Sum (buf )
23-
24- // BAD, rc4 is a weak crypto algorithm and password is sensitive data
25- rc4 .NewCipher (buf )
26-
27- // BAD, sha1 is a weak crypto algorithm and password is sensitive data
28- sha1 .Sum (buf )
29-
30- // GOOD, password is sensitive data but aes is a strong crypto algorithm
31- aes .NewCipher (buf )
32-
33- // GOOD, password is sensitive data but sha256 is a strong crypto algorithm
34- sha256 .Sum256 (buf )
35-
36- // GOOD, des is a weak crypto algorithm but public is not sensitive data
37- des .NewTripleDESCipher (public )
38-
39- // GOOD, md5 is a weak crypto algorithm but public is not sensitive data
40- md5 .Sum (public )
41-
42- // GOOD, rc4 is a weak crypto algorithm but public is not sensitive data
43- rc4 .NewCipher (public )
44-
45- // GOOD, sha1 is a weak crypto algorithm but public is not sensitive data
46- sha1 .Sum (public )
47-
48- // GOOD, aes is a strong crypto algorithm and public is not sensitive data
49- aes .NewCipher (public )
8+ func EncryptMessageWeak (key []byte , message []byte ) (dst []byte ) {
9+ // BAD, DES is a weak crypto algorithm
10+ block , _ := des .NewCipher (key )
11+ block .Encrypt (dst , message )
12+ return
13+ }
5014
51- // GOOD, sha256 is a strong crypto algorithm and public is not sensitive data
52- sha256 .Sum256 (public )
15+ func EncryptMessageStrong (key []byte , message []byte ) (dst []byte ) {
16+ // GOOD, AES is a weak crypto algorithm
17+ block , _ := aes .NewCipher (key )
18+ block .Encrypt (dst , message )
19+ return
5320}
0 commit comments