{"record":{"id":"8d3012e63a4957eb","repo":"AlexxIT/go2rtc","slug":"not-an-rsa-public-key","errorCode":null,"errorMessage":"not an RSA public key","messagePattern":"not an RSA public key","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/tuya/helper.go","lineNumber":38,"sourceCode":"\t// Hash password with MD5\n\thasher := md5.New()\n\thasher.Write([]byte(password))\n\thashedPassword := hex.EncodeToString(hasher.Sum(nil))\n\n\t// Decode PEM public key\n\tblock, _ := pem.Decode([]byte(\"-----BEGIN PUBLIC KEY-----\\n\" + pbKey + \"\\n-----END PUBLIC KEY-----\"))\n\tif block == nil {\n\t\treturn \"\", errors.New(\"failed to decode PEM block\")\n\t}\n\n\tpubKey, err := x509.ParsePKIXPublicKey(block.Bytes)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\trsaPubKey, ok := pubKey.(*rsa.PublicKey)\n\tif !ok {\n\t\treturn \"\", errors.New(\"not an RSA public key\")\n\t}\n\n\t// Encrypt with RSA\n\tencrypted, err := rsa.EncryptPKCS1v15(cryptoRand.Reader, rsaPubKey, []byte(hashedPassword))\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\t// Convert to hex string\n\treturn hex.EncodeToString(encrypted), nil\n}\n\nfunc IsEmailAddress(input string) bool {\n\temailRegex := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$`)\n\treturn emailRegex.MatchString(input)\n}\n\nfunc CreateHTTPClientWithSession() *http.Client {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/tuya/helper.go#L20-L56","documentation":"Tuya EncryptPassword type guard: the PKIX public key parsed successfully but is not *rsa.PublicKey (e.g. ECDSA or Ed25519). The password-encryption path requires RSA PKCS1v15, so a non-RSA key blob from the server/API response cannot be used.","triggerScenarios":"Thrown at pkg/tuya/helper.go:38 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the API returned an RSA public key as Tuya normally does","Check for endpoint/firmware variants that issue ECC keys and handle or avoid them","Type-assert and branch on the key algorithm at the call site"],"exampleFix":null,"handlingStrategy":"type-guard","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"}