joyent/node — Issue #2272: Hash.update does not assume utf-8 encoding by default #crypto
Author: mlangenberg
Created: 2011-12-05 13:30:08+00:00
State: open

This actually bit me on a production system because expected everything to be utf-8 by default. The last digest is correct.

```
> require('crypto').createHash('sha256').update('ë').digest('hex')
'f8d20e598df20877e4d826246fc31ffb4615cbc059aec9ec8e5b28951d844a3f'
> require('crypto').createHash('sha256').update('ë', 'utf-8').digest('hex')
'b19cfb01639de63ec3d32df67b70cb7a56316f9ef5186fd290293abbcf0b8867'
```

Now I looked into the code to see if I could find something obvious, but it looks like it uses [ParseEncoding](https://github.com/joyent/node/blob/master/src/node_crypto.cc#L2947) which is [used everywhere](https://github.com/joyent/node/blob/master/src/node.cc#L984) in Node.

I am probably missing something obvious, but is there any reason for utf-8 not being the default?