decryptSegment decrypts a path segment
(ciphertext string)
| 286 | |
| 287 | // decryptSegment decrypts a path segment |
| 288 | func (c *Cipher) decryptSegment(ciphertext string) (string, error) { |
| 289 | if ciphertext == "" { |
| 290 | return "", nil |
| 291 | } |
| 292 | rawCiphertext, err := c.fileNameEnc.DecodeString(ciphertext) |
| 293 | if err != nil { |
| 294 | return "", err |
| 295 | } |
| 296 | if len(rawCiphertext)%nameCipherBlockSize != 0 { |
| 297 | return "", ErrorNotAMultipleOfBlocksize |
| 298 | } |
| 299 | if len(rawCiphertext) == 0 { |
| 300 | // not possible if decodeFilename() working correctly |
| 301 | return "", ErrorTooShortAfterDecode |
| 302 | } |
| 303 | if len(rawCiphertext) > 2048 { |
| 304 | return "", ErrorTooLongAfterDecode |
| 305 | } |
| 306 | paddedPlaintext := eme.Transform(c.block, c.nameTweak[:], rawCiphertext, eme.DirectionDecrypt) |
| 307 | plaintext, err := pkcs7.Unpad(nameCipherBlockSize, paddedPlaintext) |
| 308 | if err != nil { |
| 309 | return "", err |
| 310 | } |
| 311 | return string(plaintext), err |
| 312 | } |
| 313 | |
| 314 | // Simple obfuscation routines |
| 315 | func (c *Cipher) obfuscateSegment(plaintext string) string { |