https://github.com/magiclen/ts-short-crypt
ShortCrypt is a very simple encryption library, which aims to encrypt any data into something random at first glance.
https://github.com/magiclen/ts-short-crypt
short-crypt typescript
Last synced: about 1 year ago
JSON representation
ShortCrypt is a very simple encryption library, which aims to encrypt any data into something random at first glance.
- Host: GitHub
- URL: https://github.com/magiclen/ts-short-crypt
- Owner: magiclen
- License: mit
- Created: 2021-05-28T08:29:32.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-22T03:29:54.000Z (over 1 year ago)
- Last Synced: 2025-03-24T17:55:20.884Z (about 1 year ago)
- Topics: short-crypt, typescript
- Language: TypeScript
- Homepage:
- Size: 757 KB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ShortCrypt
====================
[](https://github.com/magiclen/ts-short-crypt/actions/workflows/ci.yml)
ShortCrypt is a very simple encryption library, which aims to encrypt any data into something random at first glance. Even if these data are similar, the ciphers are still pretty different. The most important thing is that a cipher is only **4 bits** larger than its plaintext so that it is suitable for data used in an URL or a QR Code. Besides these, it is also an ideal candidate for serial number generation.
## Usage
```typescript
import { ShortCrypt } from "short-crypt";
```
Then, create a `ShortCrypt` instance with a key (string).
```javascript
const sc = new ShortCrypt(key);
```
For encryption, you can choose to use one of these following methods:
* `encrypt`: encrypts data to an object, a cipher separated into **base** and **body**
* `encryptToURLComponent`: encrypts data to a string suitably concatenated with URLs
* `encryptToQRCodeAlphanumeric`: encrypts data to a string with the compatibility with QR code alphanumeric mode
Only a string or a byte array can be encrypted.
```javascript
const cipher1 = sc.encryptToURLComponent(plainText);
const cipher2 = sc.encryptToQRCodeAlphanumeric(plainText);
```
For decryption, you can use `decrypt`, `decryptURLComponent`, or `decryptQRCodeAlphanumeric` method.
```javascript
const result1 = sc.decryptURLComponent(cipher1);
const result2 = sc.decryptQRCodeAlphanumeric(cipher2);
```
## Usage for Browsers
[Source](demo.html)
[Demo Page](https://rawcdn.githack.com/magiclen/ts-short-crypt/master/demo.html)
## License
[MIT](LICENSE)