Advertisement
FlyFar

keys.go

Dec 17th, 2023
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.73 KB | Cybersecurity | 0 0
  1. package main
  2.  
  3. import (
  4.     "crypto/rand"
  5.     "crypto/rsa"
  6.     "crypto/x509"
  7.     "encoding/pem"
  8. )
  9.  
  10. // Generate new RSA keypair
  11. func Generate() *rsa.PrivateKey {
  12.     priv, err := rsa.GenerateKey(rand.Reader, Bits)
  13.  
  14.     if err != nil {
  15.         panic(err)
  16.     }
  17.  
  18.     return priv
  19. }
  20.  
  21. // Stringify private key
  22. func Stringify(priv *rsa.PrivateKey) string {
  23.     privateKeyDer := x509.MarshalPKCS1PrivateKey(priv)
  24.     privateKeyBlock := pem.Block{
  25.         Type:    "RSA PRIVATE KEY",
  26.         Headers: nil,
  27.         Bytes:   privateKeyDer,
  28.     }
  29.  
  30.     return string(pem.EncodeToMemory(&privateKeyBlock))
  31. }
  32.  
  33. // DecodeKey
  34. func DecodeKey(key []byte) (*rsa.PrivateKey, error) {
  35.     block, _ := pem.Decode([]byte(key))
  36.  
  37.     priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
  38.  
  39.     return priv, err
  40. }
Tags: ransomware go PoC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement