12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package crypto
- import (
- "fmt"
- )
- import (
- "github.com/spf13/cobra"
- )
- import (
- "protocol-server/common"
- )
- var (
- orig string
- StartCmd = &cobra.Command{
- Use: "crypto",
- Short: "crypto",
- Example: "protocol-server crypto -o 123456",
- PreRun: func(cmd *cobra.Command, args []string) {
- },
- RunE: func(cmd *cobra.Command, args []string) error {
- return run()
- },
- }
- )
- func init() {
- StartCmd.Flags().StringVarP(&orig, "orig", "o", "", "orig")
- }
- func run() error {
- ciphertext, err := common.DBPwdEncrypt([]byte(orig))
- if err != nil {
- fmt.Println("Error encrypting:", err)
- return err
- }
- fmt.Printf("Ciphertext: %x\n", ciphertext)
- decryptedtext, err := common.DBPwdDecrypt(ciphertext)
- if err != nil {
- fmt.Println("Error decrypting:", err)
- return err
- }
- fmt.Printf("Decryptedtext: %s\n", string(decryptedtext))
- return nil
- }
|