| 83 | } |
| 84 | |
| 85 | func TestEncryptDecryptCases(t *testing.T) { |
| 86 | defaultLevel := log.GetLevel() |
| 87 | log.SetLevel(log.DebugLevel) |
| 88 | defer log.SetLevel(defaultLevel) |
| 89 | Convey("encrypt & decrypt cases", t, func() { |
| 90 | for i, c := range testCases { |
| 91 | in, _ := hex.DecodeString(c.raw) |
| 92 | pass := []byte(c.pass) |
| 93 | out, _ := hex.DecodeString(c.possibleEncrypted) |
| 94 | log.Infof("TestEncryptDecryptCases: %d", i) |
| 95 | enc, err := Encrypt(in, pass) |
| 96 | log.Debugf("Enc: %x", enc) |
| 97 | So(err, ShouldBeNil) |
| 98 | dec1, err := Decrypt(enc, pass) |
| 99 | if !bytes.Equal(dec1, in) { |
| 100 | t.Errorf("\nExpected:\n%x\nActual:\n%x\n", in, dec1) |
| 101 | } |
| 102 | dec2, err := Decrypt(out, pass) |
| 103 | So(err, ShouldBeNil) |
| 104 | if !bytes.Equal(dec2, in) { |
| 105 | t.Errorf("\nExpected:\n%x\nActual:\n%x\n", in, dec2) |
| 106 | } |
| 107 | } |
| 108 | }) |
| 109 | } |
| 110 | |
| 111 | func TestEncryptDecrypt(t *testing.T) { |
| 112 | var password = "CovenantSQL.io" |