示例#1
0
文件: model.go 项目: keep94/vsafe
// Encrypt encrypts sensitive fields in this instance using key namely
// UName, Password, and Special
func (e *Entry) Encrypt(key *Key) (err error) {
	if e.UName, err = aes.Encrypt(e.UName, key.Value); err != nil {
		return err
	}
	if e.Password, err = aes.Encrypt(e.Password, key.Value); err != nil {
		return err
	}
	if e.Special, err = aes.Encrypt(e.Special, key.Value); err != nil {
		return err
	}
	e.Owner = key.Id
	return
}
示例#2
0
文件: aes_test.go 项目: keep94/vsafe
func TestEncryptsSameTextDifferently(t *testing.T) {
	encoded, err := aes.Encrypt("aardvark", someKey)
	if err != nil {
		t.Fatal(err)
	}
	encodedAgain, err := aes.Encrypt("aardvark", someKey)
	if err != nil {
		t.Fatal(err)
	}
	if encoded == encodedAgain {
		t.Error("Expected same text to be encrypted differently every time.")
	}
}
示例#3
0
文件: aes_test.go 项目: keep94/vsafe
func TestEncryptSecurity(t *testing.T) {
	anotherKey := []byte("12345678901234567890123456789013")
	encoded, err := aes.Encrypt("aardvark", someKey)
	if err != nil {
		t.Fatal(err)
	}
	decoded, _ := aes.Decrypt(encoded, anotherKey)
	if decoded == "aardvark" {
		t.Error("Expected different decryption with different key")
	}
}
示例#4
0
文件: aes_test.go 项目: keep94/vsafe
func verifyEncryptDecrypt(t *testing.T, plain string) {
	encoded, err := aes.Encrypt(plain, someKey)
	if err != nil {
		t.Fatal(err)
	}
	decoded, err := aes.Decrypt(encoded, someKey)
	if err != nil {
		t.Fatal(err)
	}
	if decoded != plain {
		t.Errorf("Expected to get same thing back: '%s', got '%s' %d %d", plain, decoded, len(plain), len(decoded))
	}
}