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

Function Encrypt

crypt.go:163–189  ·  view source on GitHub ↗

Encrypt API encrypt data with the password.

(raw []byte, opts *Options)

Source from the content-addressed store, hash-verified

161
162// Encrypt API encrypt data with the password.
163func 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.
192func extractPart(doc *mscfb.Reader) ([]byte, []byte, error) {

Callers 1

WriteToBufferMethod · 0.85

Calls 4

standardKeyEncryptionMethod · 0.95
encryptMethod · 0.95
putMethod · 0.95
writeMethod · 0.95

Tested by

no test coverage detected