mirror of
https://github.com/securego/gosec.git
synced 2024-11-05 19:45:51 +00:00
38 lines
773 B
Go
38 lines
773 B
Go
|
package testutils
|
||
|
|
||
|
import "github.com/securego/gosec/v2"
|
||
|
|
||
|
var (
|
||
|
// SampleCodeG502 - Blocklisted import DES
|
||
|
SampleCodeG502 = []CodeSample{
|
||
|
{[]string{`
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"crypto/cipher"
|
||
|
"crypto/des"
|
||
|
"crypto/rand"
|
||
|
"encoding/hex"
|
||
|
"fmt"
|
||
|
"io"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
block, err := des.NewCipher([]byte("sekritz"))
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
plaintext := []byte("I CAN HAZ SEKRIT MSG PLZ")
|
||
|
ciphertext := make([]byte, des.BlockSize+len(plaintext))
|
||
|
iv := ciphertext[:des.BlockSize]
|
||
|
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
stream := cipher.NewCFBEncrypter(block, iv)
|
||
|
stream.XORKeyStream(ciphertext[des.BlockSize:], plaintext)
|
||
|
fmt.Println("Secret message is: %s", hex.EncodeToString(ciphertext))
|
||
|
}
|
||
|
`}, 1, gosec.NewConfig()},
|
||
|
}
|
||
|
)
|