You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
847 B

  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "net/http"
  7. ownrsa "./ownrsa"
  8. "github.com/fatih/color"
  9. )
  10. func readKeys(path string) []ownrsa.PackRSA {
  11. var keys []ownrsa.PackRSA
  12. file, err := ioutil.ReadFile(path)
  13. check(err)
  14. content := string(file)
  15. json.Unmarshal([]byte(content), &keys)
  16. return keys
  17. }
  18. func saveKeys(keys []ownrsa.PackRSA, path string) {
  19. jsonKeys, err := json.Marshal(keys)
  20. check(err)
  21. err = ioutil.WriteFile(path, jsonKeys, 0644)
  22. check(err)
  23. }
  24. func getServerPubK(url string) ownrsa.RSAPublicKey {
  25. r, err := http.Get(url + "/")
  26. check(err)
  27. fmt.Println(r)
  28. decoder := json.NewDecoder(r.Body)
  29. //var sigmaString string
  30. var pubK ownrsa.RSAPublicKey
  31. err = decoder.Decode(&pubK)
  32. if err != nil {
  33. panic(err)
  34. }
  35. defer r.Body.Close()
  36. color.Blue("received server pubK:")
  37. fmt.Println(pubK)
  38. return pubK
  39. }