crypto.go 849 B

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