Exemple #1
0
func Decrypt(text, key []byte) ([]byte, error) {
	// Create cipher and pad text
	cipher, padded, err := cipherAndPaddedText(text, key)
	if err != nil {
		return nil, err
	}

	keysize := len(key)

	// Decrypt each block
	for i := 0; i < len(padded); i += keysize {
		cipher.Decrypt(padded[i:i+keysize], padded[i:i+keysize])
	}

	return padded[:len(text)], nil
}
Exemple #2
0
// Authenticate and start a session
func (m *Mega) Login(email string, passwd string) error {
	var msg [1]LoginMsg
	var res [1]LoginResp
	var err error
	var result []byte

	passkey := password_key(passwd)
	uhandle := stringhash(email, passkey)
	m.uh = make([]byte, len(uhandle))
	copy(m.uh, uhandle)

	msg[0].Cmd = "us"
	msg[0].User = email
	msg[0].Handle = string(uhandle)

	req, _ := json.Marshal(msg)
	result, err = m.api_request(req)

	if err != nil {
		return err
	}

	err = json.Unmarshal(result, &res)
	if err != nil {
		return err
	}

	m.k = base64urldecode([]byte(res[0].Key))
	cipher, err := aes.NewCipher(passkey)
	cipher.Decrypt(m.k, m.k)
	m.sid = decryptSessionId([]byte(res[0].Privk), []byte(res[0].Csid), m.k)

	if err != nil {
		return err
	}

	err = m.getFileSystem()

	return err
}