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)
| 401 | // Support cryptographic algorithm: MD4, MD5, RIPEMD-160, SHA1, SHA256, |
| 402 | // SHA384 and SHA512. |
| 403 | func 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. |
| 429 | func convertPasswdToKey(passwd string, blockKey []byte, encryption Encryption) (key []byte, err error) { |