Description
A 1024-bit RSA key falls short of the strength needed for new keys. The cost of recovering a private key depends on its length, how it is used and the computing resources available.
Potential impact
A recovered private key may expose data encrypted for it or allow forged signatures. Long-lived ciphertext and certificates can outlast the key’s protection.
Remediation
- Enforce a minimum of 2048 bits for new RSA keys. Consider 3072 bits or more for longer protection or stricter policies. Check library and service support, including older settings that still allow 1024 bits.
- Before replacing a short key, identify the certificates, signature verifiers and ciphertext that depend on it. Before retiring the old key, verify you can still decrypt the data you need after migration.
Examples
Before
go
package main
import (
"crypto/rand"
"crypto/rsa"
"log"
)
// Before: generate a 1024-bit RSA key
func generateWeakRSAKey() *rsa.PrivateKey {
// 1024 bits is insufficient for a new security design
keySize := 1024
priv, err := rsa.GenerateKey(rand.Reader, keySize)
if err != nil {
log.Fatalf("failed to generate RSA key: %v", err)
}
return priv
}
func main() {
_ = generateWeakRSAKey()
}
After
go
package main
import (
"crypto/rand"
"crypto/rsa"
"log"
)
const (
// Recommended minimum: 2048 bits
MinRSAKeySize = 2048
)
// After: generate an RSA key of at least 2048 bits
func generateStrongRSAKey() *rsa.PrivateKey {
keySize := MinRSAKeySize
priv, err := rsa.GenerateKey(rand.Reader, keySize)
if err != nil {
log.Fatalf("failed to generate RSA key: %v", err)
}
return priv
}
func main() {
_ = generateStrongRSAKey()
}
MinRSAKeySize passes 2048 bits to rsa.GenerateKey in this example. Use a cryptographic random source, protect the private key and select the appropriate signing or encryption scheme.