Skip to content
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

Binary and base64 ouput added #23

Open
wants to merge 1 commit 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
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ sha512_224('中文'); // 0f46a0ae7f226517dd66ece0ce1efa29ffb7ced05ac4566fdcaed18
// Different output
sha512(''); // cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
sha512.hex(''); // cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
sha512.hexBase64(''); // Y2Y4M2UxMzU3ZWVmYjhiZGYxNTQyODUwZDY2ZDgwMDdkNjIwZTQwNTBiNTcxNWRjODNmNGE5MjFkMzZjZTljZTQ3ZDBkMTNjNWQ4NWYyYjBmZjgzMThkMjg3N2VlYzJmNjNiOTMxYmQ0NzQxN2E4MWE1MzgzMjdhZjkyN2RhM2U=
sha512.array(''); // [207, 131, 225, 53, 126, 239, 184, 189, 241, 84, 40, 80, 214, 109, 128, 7, 214, 32, 228, 5, 11, 87, 21, 220, 131, 244, 169, 33, 211, 108, 233, 206, 71, 208, 209, 60, 93, 133, 242, 176, 255, 131, 24, 210, 135, 126, 236, 47, 99, 185, 49, 189, 71, 65, 122, 129, 165, 56, 50, 122, 249, 39, 218, 62]
sha512.digest(''); // [207, 131, 225, 53, 126, 239, 184, 189, 241, 84, 40, 80, 214, 109, 128, 7, 214, 32, 228, 5, 11, 87, 21, 220, 131, 244, 169, 33, 211, 108, 233, 206, 71, 208, 209, 60, 93, 133, 242, 176, 255, 131, 24, 210, 135, 126, 236, 47, 99, 185, 49, 189, 71, 65, 122, 129, 165, 56, 50, 122, 249, 39, 218, 62]
sha512.arrayBuffer(''); // ArrayBuffer
sha512.binary(''); // Ï�á5~︽ñT(PÖm��Ö ä��W�Ü�ô©!ÓléÎGÐÑ<]�ò°ÿ��Ò�~ì/c¹1½GAz�¥82zù'Ú>
sha512.binaryBase64(''); // z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==
```

## License
Expand Down
18 changes: 17 additions & 1 deletion src/sha512.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
0x5FCB6FAB, 0x3AD6FAEC, 0x6C44198C, 0x4A475817
];

var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
var OUTPUT_TYPES = ['hex', 'hexBase64', 'array', 'digest', 'arrayBuffer', 'binary', 'binaryBase64'];

var blocks = [];

Expand Down Expand Up @@ -722,6 +722,10 @@

Sha512.prototype.toString = Sha512.prototype.hex;

Sha512.prototype.hexBase64 = function () {
return btoa(this.hex());
};

Sha512.prototype.digest = function () {
this.finalize();

Expand Down Expand Up @@ -765,6 +769,18 @@

Sha512.prototype.array = Sha512.prototype.digest;

Sha512.prototype.binary = function () {
return this.digest()
.map(function (v) {
return String.fromCharCode(v);
})
.join('');
};

Sha512.prototype.binaryBase64 = function () {
return btoa(this.binary());
};

Sha512.prototype.arrayBuffer = function () {
this.finalize();

Expand Down