MCPcopy
hub / github.com/qax-os/excelize / agileDecrypt

Function agileDecrypt

crypt.go:403–426  ·  view source on GitHub ↗

ECMA-376 Agile Encryption agileDecrypt decrypt the CFB file format with ECMA-376 agile encryption. Support cryptographic algorithm: MD4, MD5, RIPEMD-160, SHA1, SHA256, SHA384 and SHA512.

(encryptionInfoBuf, encryptedPackageBuf []byte, opts *Options)

Source from the content-addressed store, hash-verified

401// Support cryptographic algorithm: MD4, MD5, RIPEMD-160, SHA1, SHA256,
402// SHA384 and SHA512.
403func agileDecrypt(encryptionInfoBuf, encryptedPackageBuf []byte, opts *Options) (packageBuf []byte, err error) {
404 var encryptionInfo Encryption
405 if encryptionInfo, err = parseEncryptionInfo(encryptionInfoBuf[8:]); err != nil {
406 return
407 }
408 // Convert the password into an encryption key.
409 key, err := convertPasswdToKey(opts.Password, blockKey, encryptionInfo)
410 if err != nil {
411 return
412 }
413 // Use the key to decrypt the package key.
414 encryptedKey := encryptionInfo.KeyEncryptors.KeyEncryptor[0].EncryptedKey
415 saltValue, err := base64.StdEncoding.DecodeString(encryptedKey.SaltValue)
416 if err != nil {
417 return
418 }
419 encryptedKeyValue, err := base64.StdEncoding.DecodeString(encryptedKey.EncryptedKeyValue)
420 if err != nil {
421 return
422 }
423 packageKey, _ := decrypt(key, saltValue, encryptedKeyValue)
424 // Use the package key to decrypt the package.
425 return decryptPackage(packageKey, encryptedPackageBuf, encryptionInfo)
426}
427
428// convertPasswdToKey convert the password into an encryption key.
429func convertPasswdToKey(passwd string, blockKey []byte, encryption Encryption) (key []byte, err error) {

Callers 2

TestEncryptFunction · 0.85
DecryptFunction · 0.85

Calls 4

parseEncryptionInfoFunction · 0.85
convertPasswdToKeyFunction · 0.85
decryptFunction · 0.85
decryptPackageFunction · 0.85

Tested by 1

TestEncryptFunction · 0.68