Search found 9 matches

by allcam
2025年 Jan 4日 15:33
Forum: Cloud/SaaS Development
Topic: Encryption for Smart Lock API
Replies: 12
Views: 12571

Re: Encryption for Smart Lock API

find a solution: when decrypt the ticketKey, use aes-256-ecb and the full "Access Secret/Client Secret" as key, convert the decipher to utf-8 which is 16 bytes and can be used to encrypt the Temporary Password but use aes-128-ecb instead Here is my code: // Decrypt the temporary ticketKey,...
by allcam
2025年 Jan 4日 15:24
Forum: 云开发
Topic: 智能锁 临时密码 ticketKey 解密 加密 问题
Replies: 7
Views: 1059

Re: 智能锁 临时密码 ticketKey 解密 加密 问题

谢谢大神,使用aes-256-ecb就可以直接使用完整的SECRET_KEY进行解密 就好了。后面对临时密码的加密还是要使用 aes-128-ecb

by allcam
2025年 Jan 1日 21:05
Forum: 云开发
Topic: 智能锁 临时密码 ticketKey 解密 加密 问题
Replies: 7
Views: 1059

Re: 智能锁 临时密码 ticketKey 解密 加密 问题

这是目前所用的代码,但是涂鸦显示 illegal param 错误码 1109,基本上可以确定还是加密解密过程错误: // Decrypt the temporary key using AES-128-ECB const decryptTicketKey = (encryptedKey, TUYA_SECRET_KEY) => { try { const decipher = crypto.createDecipheriv('aes-128-ecb', Buffer.from(TUYA_SECRET_KEY.substring(8, 24), 'utf8'), null); decipher...
by allcam
2025年 Jan 1日 20:52
Forum: 云开发
Topic: 智能锁 临时密码 ticketKey 解密 加密 问题
Replies: 7
Views: 1059

Re: 智能锁 临时密码 ticketKey 解密 加密 问题

这是目前所用的代码,但是涂鸦显示 illegal param 错误码 1109,基本上可以确定还是加密解密过程错误:

by allcam
2025年 Jan 1日 19:00
Forum: 云开发
Topic: 智能锁 临时密码 ticketKey 解密 加密 问题
Replies: 7
Views: 1059

Re: 智能锁 临时密码 ticketKey 解密 加密 问题

如果把AccessKey的全部32位字符当做 HEX,这就相当于 二进制里的 16位,刚好可以作为密钥对 ticketKey 进行AES-128解密, 得到的字符串也是 32位,如果把其当做 HEX 也刚好可以作为密钥对 临时密码 进行AES-128加密,可以得到一个32位的HEX字符串. 但是涂鸦同样显示 illegal param 错误

by allcam
2025年 Jan 1日 16:02
Forum: 云开发
Topic: 智能锁 临时密码 ticketKey 解密 加密 问题
Replies: 7
Views: 1059

Re: 智能锁 临时密码 ticketKey 解密 加密 问题

accessKey是您项目的Access Secret信息,使用 AccessKey的中间 16 位字符(ACCESS_KEY.substring(8, 24))对数据进行AES解密。 谢谢高人指点。 还是有点问题: 从涂鸦收到的加密的ticketKey 为 64位 HEX, 用AccessKey的中间 16 位字符(ACCESS_KEY.substring(8, 24))对数据进行AES解密后得到的字符串长度为 32位, 这不能作为密钥用于AES-128加密 临时密码,因为AES-128加密的密钥要求为 16位。如果只截取前面的 16位作为密钥来加密 临时密码, 涂鸦会显示 illegal...
by allcam
2024年 Dec 31日 08:12
Forum: Cloud/SaaS Development
Topic: Encryption for Smart Lock API
Replies: 12
Views: 12571

Re: Encryption for Smart Lock API

if I use the first 16 bytes of the access key as the AES-128 decryption key, I do get a 16-byte string with 16-byte padding from ticket key. Then I can encrypt the Tempoary Password with the 16-byte string, but Tuya will throw error "param is illegal >>>But if we use access key UTF-8 string, th...
by allcam
2024年 Dec 31日 07:32
Forum: Cloud/SaaS Development
Topic: Encryption for Smart Lock API
Replies: 12
Views: 12571

Re: Encryption for Smart Lock API

I figured this out. Turns out the access key should be interpreted as an ASCII or UTF-8 string, and not a hex string, for the encryption key. Thus, ticket_key is decrypted as a 128-bit key with 128-bits of padding, not 256 bits total. But if we use access key UTF-8 string, then it is too long for A...
by allcam
2024年 Dec 31日 04:56
Forum: 云开发
Topic: 智能锁 临时密码 ticketKey 解密 加密 问题
Replies: 7
Views: 1059

智能锁 临时密码 ticketKey 解密 加密 问题

按API接口说明, 为智能锁 设置 临时密码 时必须先通过涂鸦API 获取为临时密码加密的密钥 (ticketKey), 但是收到的密钥也是加密的,必须用 TUYA_ACCESS_KEY 解密。下面是我用的 js 代码, 我遇到的问题是: 用 TUYA_ACCESS_KEY 作密钥解密 ticketKey 时发现, 其长度是 32 字节,但AES-128-ECB支持的密钥长度是16字节,只好截出前面 16字节作为密钥,但涂鸦的API接口说明里面没有提到这一点。不过用这个办法解密能得到一个长度为 16字节的二进制的字符串 (转换为可正常显示的 十六进制 字符串为 32 位) 当用得到的二进制的字...