🔒 Huawei Modem Encryption
A JavaScript library for RSA encryption used by Huawei modems. This library provides functionality to encrypt passwords and other sensitive data using RSA PKCS#1 with both padding types.
📦 Installation
npm install huawei-modem-encryption
🚀 Usage
import { doRSAEncrypt } from 'huawei-modem-encryption';
// Example usage with OAEP padding:
const encryptedString = doRSAEncrypt(
"password", // 🔑 String to encrypt
publicKeyN, // 🔐 RSA public key modulus (n)
publicKeyE, // 🔐 RSA public key exponent (e)
"1" // 🔒 RSA padding type: "1" or 1 for OAEP
);
// Example usage with PKCS#1 v1.5 padding:
const encryptedString2 = doRSAEncrypt(
"password", // 🔑 String to encrypt
publicKeyN, // 🔐 RSA public key modulus (n)
publicKeyE, // 🔐 RSA public key exponent (e)
"0" // 🔒 RSA padding type: "0", 0, or any other value for PKCS#1 v1.5
);
📝 Parameters
encstring
: The data to be encrypted (e.g., password) 🔑encpubkeyn
: The RSA public key modulus (n) 🔐encpubkeye
: The RSA public key exponent (e) 🔐rsaPaddingType
: RSA padding type -"1"
or1
for OAEP padding, any other value (like"0"
,0
, etc.) for PKCS#1 v1.5 padding 🔒
Note: The public key (
n
ande
) should be obtained from your Huawei modem's API or documentation.
✨ Features
- 🔐 RSA encryption with dual padding support:
- PKCS#1 v1.5 padding (default) - Compatible with most Huawei modems
- OAEP padding - Enhanced security with SHA-1 hashing
- 📜 Base64 encoding of input data before encryption
- 🎲 Built-in secure random number generation
- 🛡️ SHA-1 hashing for OAEP padding
- 📦 Chunked encryption - Handles large data by splitting into appropriate chunks based on padding type
📜 License
BSD License
This package contains code derived from Tom Wu's RSA implementation.
Copyright (c) 2005 Tom Wu
All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
👨💻 Authors
Original Author: Tom Wu
Republished by: Doni Setiawan
This is a republished version of a Huawei modem encryption implementation.