From 4bd2ed0c1df5e4e2bc26543e49c1b1e7f08f4ea9 Mon Sep 17 00:00:00 2001 From: j-shomo Date: Thu, 28 Aug 2025 17:28:36 -0400 Subject: [PATCH] add code for triple des encrypting a payload --- encryption/des.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 encryption/des.go diff --git a/encryption/des.go b/encryption/des.go new file mode 100644 index 0000000..292cc8d --- /dev/null +++ b/encryption/des.go @@ -0,0 +1,33 @@ +package encryption + +import ( + "bytes" + "crypto/cipher" + "crypto/des" + + "github.com/vulncheck-oss/go-exploit/output" +) + +func PKCS5Padding(src []byte, blockSize int) []byte { + padding := blockSize - len(src)%blockSize + padtext := bytes.Repeat([]byte{byte(padding)}, padding) + + return append(src, padtext...) +} + +func TripleDesEncryption(key, iv, plainText []byte) ([]byte, bool) { + block, err := des.NewTripleDESCipher(key) + if err != nil { + output.PrintFrameworkError(err.Error()) + + return nil, false + } + + blockSize := block.BlockSize() + origData := PKCS5Padding(plainText, blockSize) + blockMode := cipher.NewCBCEncrypter(block, iv) + cryted := make([]byte, len(origData)) + blockMode.CryptBlocks(cryted, origData) + + return cryted, true +}