Skip to content

Commit 4bd2ed0

Browse files
committed
add code for triple des encrypting a payload
1 parent c621f4c commit 4bd2ed0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

encryption/des.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package encryption
2+
3+
import (
4+
"bytes"
5+
"crypto/cipher"
6+
"crypto/des"
7+
8+
"github.com/vulncheck-oss/go-exploit/output"
9+
)
10+
11+
func PKCS5Padding(src []byte, blockSize int) []byte {
12+
padding := blockSize - len(src)%blockSize
13+
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
14+
15+
return append(src, padtext...)
16+
}
17+
18+
func TripleDesEncryption(key, iv, plainText []byte) ([]byte, bool) {
19+
block, err := des.NewTripleDESCipher(key)
20+
if err != nil {
21+
output.PrintFrameworkError(err.Error())
22+
23+
return nil, false
24+
}
25+
26+
blockSize := block.BlockSize()
27+
origData := PKCS5Padding(plainText, blockSize)
28+
blockMode := cipher.NewCBCEncrypter(block, iv)
29+
cryted := make([]byte, len(origData))
30+
blockMode.CryptBlocks(cryted, origData)
31+
32+
return cryted, true
33+
}

0 commit comments

Comments
 (0)