Go

Go

Made by DeepSource

RSA key length less than 2048 bits GSC-G403

Security
Major
a05 a02 cwe-310 owasp top 10

The strength of public-key-based cryptographic algorithm (like RSA) is determined by the time that it takes to derive the private key by using brute-force methods. RSA claims that 1024-bit keys are likely to become crackable some time between 2006 and 2010 and that 2048-bit keys are sufficient until 2030.

Increase the key length to atleast 2048 bits - https://en.wikipedia.org/wiki/Key_size

Bad practice

package main
import (
    "crypto/rand"
    "crypto/rsa"
    "fmt"
)
func main() {
    //Generate Private Key
    pvk, err := rsa.GenerateKey(rand.Reader, 1024)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(pvk)
}

Recommended

package main
import (
    "crypto/rand"
    "crypto/rsa"
    "fmt"
)
func main() {
    //Generate Private Key
    pvk, err := rsa.GenerateKey(rand.Reader, 2048)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(pvk)
}

References