# js-https
**Repository Path**: ecui/js-https
## Basic Information
- **Project Name**: js-https
- **Description**: A simple demonstrational JavaScript library that makes HTTP Ajax safer.
- **Primary Language**: JavaScript
- **License**: MIT
- **Default Branch**: master
- **Homepage**: https://github.com/ErnestThePoet/js-https
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2022-10-29
- **Last Updated**: 2022-11-10
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# js-https
This little demonstrational project aims to make HTTP Ajax data transmission safer with e-envelope, which is a **much simplfied** model of TLS used behind HTTPS.
[](https://www.npmjs.org/package/js-https)
[](https://packagephobia.now.sh/result?p=js-https)
[](https://bundlephobia.com/package/js-https@latest)
[](https://npm-stat.com/charts.html?package=js-https)
## Getting Started
### Installing
Using package manager:
```bash
npm install js-https
# or
yarn add js-https
```
Or include directly in browser:
```html
```
### Overview
Now let's gain an insight into how js-https works based on e-envelope.
```
BROWSER SERVER
| |
| 1). Request site certificate |
| (containing public key) |
|----------------------------------------->|
| 2). Site certificate |
|<-----------------------------------------|
| |
| 3). Browser calls encryptRequestData() |
| (js-https generates symmetric key |
| (AES key and AES IV), encrypt them |
| using RSA with public key. Then encrypt |
| request data using AES with generated |
| symmetric key) |
| |
| 4). Browser sends ciphertext |
| (containing encrypted symmetric key |
| and request data) |
|----------------------------------------->|
| |
| 5). Server decrypts symmetric key and |
| request data, do service, then encrypts |
| response data using AES with the same |
| symmetric key |
| |
| 6). Server sends ciphertext |
| (Containing encrypted response data) |
|<-----------------------------------------|
| |
| 7). Browser calls decryptResponseData() |
| and gets the actual response object |
| (js-https decrypts response cipher |
| using AES with symmetric key) |
| |
```
The above steps 1) and 2) are not part of js-https and browser needs to verify the certificate to ensure its authority. To keep things simple, in this guide we will omit these two steps and make public key directly available in our code.
As is illustrated above, in order to get things working, js-https requires the backend server to perform RSA-decryption, AES-decryption and AES-encryption for each request. You can find our backend demo with Springboot [here](https://github.com/ErnestThePoet/js-https-backend-demo) and one with Django [here](https://github.com/ErnestThePoet/js-https-backend-demo-django).
### Generating RSA Keys
To get an RSA public/private key pair, you can take advantage of OpenSSL:
```bash
# 2048-bit key size is recommended
openssl genrsa -out private-orig.pem 2048
# Our backend demo needs PKCS#8 format key, so convert the key
openssl pkcs8 -topk8 -inform PEM -in private-orig.pem -outform pem -nocrypt -out private.pem
# Get public key from private key
openssl rsa -in private.pem -pubout -out public.pem
```
Make sure to keep your **private key** a top-secret!
### Usage
The usage is as simple as follows:
```javascript
// If you use