Skip to content

Commit

Permalink
Create crypto_weak_key_rsa_1024.go
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Brown <ericwb@users.noreply.github.com>
  • Loading branch information
ericwb authored Mar 4, 2024
1 parent 452cd07 commit 97e0458
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions go/stdlib/crypto_weak_key_rsa_1024.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// level: ERROR
// start_line: 18
// end_line: 18
// start_column: 52
// end_column: 56
package main

import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"log"
)

func main() {
// Generate the RSA key
privateKey, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
log.Fatalf("Failed to generate key: %v", err)
}

// Extract the public key from the private key
publicKey := &privateKey.PublicKey

// Encode the public key to PEM format
publicKeyBytes, err := x509.MarshalPKIXPublicKey(publicKey)
if err != nil {
log.Fatalf("Failed to marshal public key: %v", err)
}

publicKeyPEM := pem.EncodeToMemory(&pem.Block{
Type: "RSA PUBLIC KEY",
Bytes: publicKeyBytes,
})

// Print the public key
log.Println(string(publicKeyPEM))
}

0 comments on commit 97e0458

Please sign in to comment.