func (cf *Cifrador) Decrypt(desencriptar []byte) []byte { res := desencriptar rckey := cf.rckey[:] crc4, err := rc4.NewCipher(rckey) if err != nil { panic(err) } crc4.XORKeyStream(res, res) salsa20.XORKeyStream(res, res, cf.nonce, &cf.key) return res }
func load(r io.Reader, key []byte, password string) (*DB, error) { l := &loader{r: r, key: key, password: password, db: &DB{}} err := l.readFixedHeader() if err != nil { return nil, err } err = l.readDynamicHeader() if err != nil { return nil, err } err = l.readPayload() if err != nil { return nil, err } kpf := KeePassFile{} err = xml.Unmarshal(l.body, &kpf) if err != nil { return nil, err } l.db.KeePassFile = kpf err = l.removeProtect(false) if err != nil { return nil, err } // go's salsa20 library has no way to specify the offset (8-bytes of nonce) // into the stream so the entire stream needs to be decrypted via a single // operation. psk := sha256.Sum256(l.protectedStreamKey[:]) salsa20.XORKeyStream(l.pwStream, l.pwStream, protectedIV, &psk) err = l.removeProtect(true) if err != nil { return nil, err } return l.db, nil }