Skip to content

Feat: export the MD5 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ $ cat .gitignore

*.log
*.tgz
/.idea/
127 changes: 13 additions & 114 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,133 +1,32 @@
# crypto-ts

Typescript library of crypto standards. Ready for AOT and treeshaking in combination with Angular and other modern typescript frameworks.

## Node.js (Install)

Requirements:

- Node.js
- npm (Node.js package manager)

```bash
npm install crypto-ts
```
本项目是基于 crypto-ts 构建的一个标准的 ESM 格式的 crypto.js ,可以用于 avm 等支持 esm 的环境。

### Usage

ES6 import for typical API call signing use case:
将 `dist/avm` 目录下的 `crypto.min.js` 复制到项目中 `script` 目录下。

全量引入:
```javascript
import { AES } from 'crypto-ts';

const encryptedMessage = AES.encrypt('message', 'test').toString();
```

Modular include:
import CryptoJS from '../../script/crypto.min';
const encryptedMessage = CryptoJS.AES.encrypt('message', 'test').toString();

```javascript
var AES = require("crypto-ts").AES;
var SHA256 = require("crypto-ts").SHA256;
...
console.log(SHA256("Message"));
```

Including all libraries, for access to extra methods:
按需引入:

```javascript
var CryptoTS = require("crypto-ts");
...
console.log(CryptoTS.HmacSHA1("Message", "Key"));
```

## Client (browser)

Requirements:

- Node.js
- Bower (package manager for frontend)

```bash
bower install crypto-ts
```

### Usage

Modular include:

```javascript
require.config({
packages: [
{
name: 'crypto-ts',
location: 'path-to/bower_components/crypto-ts',
main: 'index'
}
]
});

require(["crypto-ts/algo/aes", "crypto-ts/algo/sha256"], function (AES, SHA256) {
console.log(SHA256("Message"));
});
```

Including all libraries, for access to extra methods:

```javascript
// Above-mentioned will work or use this simple form
require.config({
paths: {
'crypto-ts': 'path-to/bower_components/crypto-ts/crypto-ts'
}
});

require(["crypto-ts"], function (CryptoTS) {
console.log(CryptoTS.MD5("Message"));
});
```

### Usage without RequireJS

```html
<script type="text/javascript" src="path-to/bower_components/crypto-ts/crypto-ts.js"></script>
<script type="text/javascript">
var encrypted = CryptoTS.AES(...);
var encrypted = CryptoTS.SHA256(...);
</script>
```

### AES Encryption

#### Plain text encryption

```javascript
var CryptoTS = require("crypto-ts");

// Encrypt
var ciphertext = CryptoTS.AES.encrypt('my message', 'secret key 123');

// Decrypt
var bytes = CryptoTS.AES.decrypt(ciphertext.toString(), 'secret key 123');
var plaintext = bytes.toString(CryptoTS.enc.Utf8);
import {AES} from '../../script/crypto.min';
const encryptedMessage = AES.encrypt('message', 'test').toString();

console.log(plaintext);
```
### Build
从源码中构建:

#### Object encryption

```javascript
var CryptoTS = require("crypto-ts");

var data = [{id: 1}, {id: 2}]

// Encrypt
var ciphertext = CryptoTS.AES.encrypt(JSON.stringify(data), 'secret key 123');

// Decrypt
var bytes = CryptoTS.AES.decrypt(ciphertext.toString(), 'secret key 123');
var decryptedData = JSON.parse(bytes.toString(CryptoTS.enc.Utf8));

console.log(decryptedData);
```bash
node ./build-esm
```

### List of modules
Expand Down Expand Up @@ -200,4 +99,4 @@ console.log(decryptedData);
- ```crypto-ts/pad-iso10126```
- ```crypto-ts/pad-iso97971```
- ```crypto-ts/pad-zeropadding```
- ```crypto-ts/pad-nopadding```
- ```crypto-ts/pad-nopadding```
9 changes: 9 additions & 0 deletions build-esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require('esbuild').buildSync({
entryPoints: ['./src/crypto-ts.ts'],
outfile: './dist/avm/crypto.min.js',
format: 'esm',
bundle: true,
minify: true,
platform: 'node',
external: []
})
1 change: 1 addition & 0 deletions dist/avm/crypto.min.js

Large diffs are not rendered by default.

Loading