Answer the question
In order to leave comments, you need to log in
How to encrypt data in parts?
I receive data in parts (about 10 parts)
It is necessary to encrypt each part and write it to one file.
When decrypted, only the first part is correctly decrypted.
As I understand it, additional bytes are added during encryption, so the decryptor does not work correctly.
How to encrypt correctly?
I use the DES algorithm (you need to use it)
Encryption function
func Encrypt(key, iv, plainText []byte) (ciphertext []byte, err error) {
block, err := des.NewCipher(key)
if err != nil {
return nil, err
}
blockSize := block.BlockSize()
origData := pkcs5Padding(plainText, blockSize)
blockMode := cipher.NewCBCEncrypter(block, iv)
cryted := make([]byte, len(origData))
blockMode.CryptBlocks(cryted, origData)
return cryted, nil
}
func pkcs5Padding(src []byte, blockSize int) []byte {
padding := blockSize - len(src)%blockSize
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
return append(src, padtext...)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question