@mega-yfue/eufy-sdk / p2pCodec / deriveLevel2KeyFromRsaGatewayInfo
Function: deriveLevel2KeyFromRsaGatewayInfo()
function deriveLevel2KeyFromRsaGatewayInfo(gwPayload, rsaPrivateKey): Buffer<ArrayBufferLike> | undefined;Derive the P2P level-2 AES-128-ECB session key from a decrypted CMD_GATEWAYINFO (1100) payload and the RSA private key of a cipher whose get_ciphers answer carries no ECC key.
Layout of the decrypted payload: cipher_id(2 LE) ‖ 0000 ‖ RSA ciphertext ‖ …, the ciphertext as long as the key's modulus. It is the 16-byte session key under PKCS#1 v1.5 encryption padding (00 02 ‖ ≥8 non-zero bytes ‖ 00 ‖ key). The padding is checked here over the raw RSA result so a wrong key fails closed: under OpenSSL's implicit rejection, RSA_PKCS1_PADDING answers random bytes for it instead of throwing, and those can be 16 bytes long.
rsaPrivateKey is the get_ciphers private_key: base64 PKCS#8 DER.
Returns the 16-byte key, or undefined when the key does not parse, the payload is short, or the padding or key length is wrong (fails closed, never throws).
Parameters
gwPayload
Buffer
rsaPrivateKey
string
Returns
Buffer<ArrayBufferLike> | undefined