{"record":{"id":"05f4bded82a623df","repo":"AlexxIT/go2rtc","slug":"failed-to-encrypt-password-v","errorCode":null,"errorMessage":"failed to encrypt password: %v","messagePattern":"failed to encrypt password: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tuya/tuya.go","lineNumber":132,"sourceCode":"\n\t\titems = append(items, &api.Source{\n\t\t\tName: device.DeviceName,\n\t\t\tURL:  url,\n\t\t})\n\t}\n\n\tapi.ResponseSources(w, items)\n}\n\nfunc login(client *http.Client, serverHost, email, password, countryCode string) (*tuya.LoginResult, error) {\n\ttokenResp, err := getLoginToken(client, serverHost, email, countryCode)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tencryptedPassword, err := tuya.EncryptPassword(password, tokenResp.Result.PbKey)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to encrypt password: %v\", err)\n\t}\n\n\tvar loginResp *tuya.PasswordLoginResponse\n\tvar url string\n\n\tloginReq := tuya.PasswordLoginRequest{\n\t\tCountryCode: countryCode,\n\t\tPasswd:      encryptedPassword,\n\t\tToken:       tokenResp.Result.Token,\n\t\tIfEncrypt:   1,\n\t\tOptions:     `{\"group\":1}`,\n\t}\n\n\tif tuya.IsEmailAddress(email) {\n\t\turl = fmt.Sprintf(\"https://%s/api/private/email/login\", serverHost)\n\t\tloginReq.Email = email\n\t} else {\n\t\turl = fmt.Sprintf(\"https://%s/api/private/phone/login\", serverHost)","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/tuya/tuya.go#L114-L150","documentation":"Wraps an error from tuya.EncryptPassword, which failed to encrypt the user's password with the public key returned by the login-token endpoint. Indicates the Tuya password-login flow cannot proceed; surfaces to apiTuya as a login failure, typically due to an empty/invalid RSA public key from getLoginToken.","triggerScenarios":"Thrown at internal/tuya/tuya.go:132 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the account password is correct and non-empty","Retry login to obtain a fresh PbKey from the token endpoint","Check that the Tuya region/appKey configuration is valid so the token response contains a usable key"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}