You've already forked rsa-file-encryption
update branch pattern in tests.yml to allow nested branches
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 3m2s
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 3m2s
This commit is contained in:
@@ -113,14 +113,23 @@ func (f *EncryptedFile) WriteDecryptedFileToDisk(filePath string) error {
|
||||
}
|
||||
|
||||
func (f *EncryptedFile) unpackFileAndDecrypt(packedFile []byte) error {
|
||||
keyLen := f.privateKey.Size()
|
||||
|
||||
minReqLen := aes.BlockSize + keyLen + len(hmacKey)
|
||||
|
||||
if len(packedFile) < minReqLen {
|
||||
return fmt.Errorf("packed file is too short to be valid")
|
||||
}
|
||||
|
||||
if bytes.Contains(packedFile, []byte(hmacKey)) {
|
||||
parts := bytes.SplitN(packedFile, []byte(hmacKey), 2)
|
||||
packedFile, f.hmac = parts[0], parts[1]
|
||||
}
|
||||
|
||||
keyLen := f.privateKey.Size()
|
||||
|
||||
lenWithoutKey := len(packedFile) - keyLen
|
||||
if lenWithoutKey < aes.BlockSize {
|
||||
return fmt.Errorf("packed file is too short to contain valid nonce and ciphertext")
|
||||
}
|
||||
|
||||
packedFile, f.symmetricKeyEnc = packedFile[0:lenWithoutKey], packedFile[lenWithoutKey:]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user