crypto.go 861 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package crypto
  2. import (
  3. "fmt"
  4. )
  5. import (
  6. "github.com/spf13/cobra"
  7. )
  8. import (
  9. "protocol-server/common"
  10. )
  11. var (
  12. orig string
  13. StartCmd = &cobra.Command{
  14. Use: "crypto",
  15. Short: "crypto",
  16. Example: "protocol-server crypto -o 123456",
  17. PreRun: func(cmd *cobra.Command, args []string) {
  18. },
  19. RunE: func(cmd *cobra.Command, args []string) error {
  20. return run()
  21. },
  22. }
  23. )
  24. func init() {
  25. StartCmd.Flags().StringVarP(&orig, "orig", "o", "", "orig")
  26. }
  27. func run() error {
  28. ciphertext, err := common.DBPwdEncrypt([]byte(orig))
  29. if err != nil {
  30. fmt.Println("Error encrypting:", err)
  31. return err
  32. }
  33. fmt.Printf("Ciphertext: %x\n", ciphertext)
  34. decryptedtext, err := common.DBPwdDecrypt(ciphertext)
  35. if err != nil {
  36. fmt.Println("Error decrypting:", err)
  37. return err
  38. }
  39. fmt.Printf("Decryptedtext: %s\n", string(decryptedtext))
  40. return nil
  41. }