-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsymmetric_cipher.go
More file actions
39 lines (32 loc) · 1.56 KB
/
symmetric_cipher.go
File metadata and controls
39 lines (32 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// -----------------------------------------------------------------------------
// github.com/balacode/udpt /[symmetric_cipher.go]
// (c) balarabe@protonmail.com License: MIT
// -----------------------------------------------------------------------------
package udpt
// SymmetricCipher interface provides methods to initialize a symmetric-key
// cipher and use it to encrypt and decrypt plaintext.
// A symmetric-key cipher uses the same key to encrypt and decrypt.
type SymmetricCipher interface {
// ValidateKey checks if 'cryptoKey' is acceptable for use with the cipher.
// For example it must be of the right size.
ValidateKey(cryptoKey []byte) error
// SetKey initializes the cipher with the specified encryption key.
//
// If the cipher is already initialized with the given key, does nothing.
// The same key is used for encryption and decryption.
//
SetKey(cryptoKey []byte) error
// Encrypt encrypts plaintext using the key given to SetKey and
// returns the encrypted ciphertext, using a symmetric-key cipher.
//
// You need to call SetKey at least once before you call Encrypt.
//
Encrypt(plaintext []byte) (ciphertext []byte, err error)
// Decrypt decrypts ciphertext using the key given to SetKey and
// returns the decrypted plaintext, using a symmetric-key cipher.
//
// You need to call SetKey at least once before you call Decrypt.
//
Decrypt(ciphertext []byte) (plaintext []byte, err error)
} // SymmetricCipher
// end