MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / Decrypt

Function Decrypt

client/toolkit/e2ee.go:63–83  ·  view source on GitHub ↗

Decrypt decrypts data with given password by AES-128-CBC PKCS#7. iv will be read from the head of raw.

(in, password []byte)

Source from the content-addressed store, hash-verified

61// Decrypt decrypts data with given password by AES-128-CBC PKCS#7. iv will be read from
62// the head of raw.
63func Decrypt(in, password []byte) (out []byte, err error) {
64 keyE := symmetric.KeyDerivation(password, salt[:])[:16]
65 // IV + padded cipher data == (n + 1 + 1) * aes.BlockSize
66 if len(in)%aes.BlockSize != 0 || len(in)/aes.BlockSize < 2 {
67 return nil, errors.New("cipher data size not match")
68 }
69
70 // read IV
71 iv := in[:aes.BlockSize]
72
73 // start decryption, as keyE and iv are generated properly, there should
74 // not be any error
75 block, _ := aes.NewCipher(keyE)
76
77 mode := cipher.NewCBCDecrypter(block, iv)
78 // same length as cipher data
79 plainData := make([]byte, len(in)-aes.BlockSize)
80 mode.CryptBlocks(plainData, in[aes.BlockSize:])
81
82 return crypto.RemovePKCSPadding(plainData)
83}

Callers 2

TestEncryptDecryptCasesFunction · 0.85
TestEncryptDecryptFunction · 0.85

Calls 3

KeyDerivationFunction · 0.92
RemovePKCSPaddingFunction · 0.92
NewMethod · 0.65

Tested by 2

TestEncryptDecryptCasesFunction · 0.68
TestEncryptDecryptFunction · 0.68