Encrypt API encrypt data with the password.
(raw []byte, opts *Options)
| 161 | |
| 162 | // Encrypt API encrypt data with the password. |
| 163 | func Encrypt(raw []byte, opts *Options) ([]byte, error) { |
| 164 | encryptor := encryption{ |
| 165 | EncryptedVerifierHashInput: make([]byte, 16), |
| 166 | EncryptedVerifierHashValue: make([]byte, 32), |
| 167 | SaltValue: make([]byte, 16), |
| 168 | BlockSize: 16, |
| 169 | KeyBits: 128, |
| 170 | SaltSize: 16, |
| 171 | } |
| 172 | // Key Encryption |
| 173 | encryptionInfoBuffer, err := encryptor.standardKeyEncryption(opts.Password) |
| 174 | if err != nil { |
| 175 | return nil, err |
| 176 | } |
| 177 | // Package Encryption |
| 178 | encryptedPackage := make([]byte, 8) |
| 179 | binary.LittleEndian.PutUint64(encryptedPackage, uint64(len(raw))) |
| 180 | encryptedPackage = append(encryptedPackage, encryptor.encrypt(raw)...) |
| 181 | // Create a new CFB |
| 182 | compoundFile := &cfb{ |
| 183 | paths: []string{"Root Entry/"}, |
| 184 | sectors: []sector{{name: "Root Entry", typeID: 5}}, |
| 185 | } |
| 186 | compoundFile.put("EncryptionInfo", encryptionInfoBuffer) |
| 187 | compoundFile.put("EncryptedPackage", encryptedPackage) |
| 188 | return compoundFile.write(), nil |
| 189 | } |
| 190 | |
| 191 | // extractPart extract data from storage by specified part name. |
| 192 | func extractPart(doc *mscfb.Reader) ([]byte, []byte, error) { |
no test coverage detected