Node.js中的PHP哈希('sha512',$ x)等价物(Angular2,Ionic2)

I'm trying to create a SHA512 Hash in Angular2 (Ionic2) witch is similar to the PHP function hash('sha512').

I just tried crypto-js, crypto and js-sha512 modules but no matter how it is always a different Hash like in PHP.

I also converted the String into Hex with toString(CryptoJS.enc.Hex) and toString('hex') but without success.

In PHP that:

NjAxODkwYWZkODA3MDkzMjgzYWQ1>Y2YwMTA2NGRiNGFlNWE0NTM1OWY3YTExMmJmNGIxNjhi

becomes to that how its right:

a2ea72e6c572ab957987a946a7a490c4ec93e7d0a7466e71b

but in crypto it becomes to:

eac7baac918158db69d81432037d2ef5f6327d9030e5d7a

You can you the Node.js crypto package.

PHP:

hash('sha512', 'hello');

JavaScript:

const crypto = require("crypto")
const hash = crypto.createHash("sha512")

hash.update("hello world") // Hash the input
hash.digest("hex")         // Return it as a hex string

If you need to run this code in a browser, you can bundle it through browserify or webpack. Those 2 tools will use a polyfill for crypto.