Comments (9)
By the way, a related question is whether the high and low surrogate code points in the BMP are handled correctly:
The High Surrogates (U+D800–U+DBFF) and Low Surrogate (U+DC00–U+DFFF) codes are reserved for encoding non-BMP characters in UTF-16 by using a pair of 16-bit codes: one High Surrogate and one Low Surrogate. A single surrogate code point will never be assigned a character.
Are there any test cases for these code points?
from jssha.
Okay, here is a test case using a non-BMP Unicode character. The test case is for SHA-256 using the default encoding UTF8. Sample Javascript code looks like the following:
// With 'TEXT', the jsSHA constructor defaults to encoding 'UTF8'.
var shaObj = new jsSHA(s, 'TEXT');
return shaObj.getHash('SHA-256', 'HEX');
When I try the string '\ud83d\ude00'
, which is the Unicode Character 'GRINNING FACE' (U+1F600), I get the following:
ea645893a930e0872284cf8fbc8d14f66f052aea0bc8d9c4829f08a38219940c
But I believe one should instead get:
f0443a342c5ef54783a111b51ba56c938e474c32324d90c3a60c9c8e3a37e2d9
Here is Python code I used to get the expected value (tested with Python 2.7.6):
import hashlib
import json
def sha(bytes):
return hashlib.sha256(bytes).hexdigest()
def test(u):
print(json.dumps(u))
b = u.encode('utf-8')
print(repr(b))
print(sha(b))
print
# Unicode Character 'GRINNING FACE' (U+1F600)
# http://www.fileformat.info/info/unicode/char/1F600/index.htm
test(u"\U0001F600")
# Gives:
# JSON: "\ud83d\ude00"
# UTF-8: '\xf0\x9f\x98\x80'
# SHA-256: f0443a342c5ef54783a111b51ba56c938e474c32324d90c3a60c9c8e3a37e2d9
from jssha.
Any acknowledgment of this issue?
I don't think it would be too hard to fix. The Mozilla page linked in the original comment has code that can probably be used close to as is.
from jssha.
Sorry for the delay here; I have had limited computer access for the last
few weeks. I found a code snippet that should fit in nicely with my string
parsing but haven't had a chance to actually try it. If you have a patch
handy, that would speed things up.
On Tuesday, September 23, 2014, Chris Jerdonek [email protected]
wrote:
Any acknowledgment of this issue?
I don't think it would be too hard to fix. The Mozilla page linked in the
original comment has code that can probably be used close to as is.—
Reply to this email directly or view it on GitHub
#21 (comment).
from jssha.
Thanks, @Caligatio. If you already have something in mind, I'll let you take care of it. There's no rush (at least for me). I just wasn't sure if you had seen the issue.
from jssha.
I believe this should be fixed in https://github.com/Caligatio/jsSHA/blob/db68ec213c17f34eb105e9561b55045c0f7cbc65/src/sha_dev.js
Can you try out your tests to see if you come to the same conclusion?
from jssha.
Thanks! But can you make it easier to test? sha_dev.js is ignored in your bower.json, so I don't get the change when I bower install. Or else you could recompile the other files. Thanks.
from jssha.
All files should now be synced up.
from jssha.
I just had one test for this case, but it passes now. Thanks!
from jssha.
Related Issues (20)
- Method chaining when using `update` HOT 7
- Typescript build error HOT 2
- Types are packaged/exposed incorrectly HOT 2
- Can SM3 be supported? HOT 1
- Feature Request: KangarooTwelve and MarsupilamiFourteen HOT 6
- ESM package for jssha HOT 1
- How to generate the SHA3-256 hash? HOT 1
- Encrypt sha256 in c# and make it the same key HOT 4
- 43106983S HOT 1
- setHMACKey with B64 HOT 4
- Error when i create jsSHA object HOT 24
- Performance HOT 12
- Package exports do not define a valid '.' target HOT 6
- Recreate internal state HOT 6
- SCRIPT:1002 Syntax Error HOT 3
- Question : How to reset / clear for another hash? HOT 2
- Installing this package via a <script> tag HOT 2
- Deno support documentation
- Reading custom amount of bytes with SHAKE HOT 2
- Incorrect project website in README.md HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jssha.