# Ionic 4 can't perform sha256 hashing with key using crypto-js

**URL:** <https://forum.ionicframework.com/t/ionic-4-cant-perform-sha256-hashing-with-key-using-crypto-js/183184>\
**Category:** Ionic Framework\
**Created:** [February 12, 2020, 12:10pm UTC](https://forum.ionicframework.com/t/ionic-4-cant-perform-sha256-hashing-with-key-using-crypto-js/183184 "2020-02-12T12:10:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pratikjaiswa15](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@Pratikjaiswa15](https://forum.ionicframework.com/u/Pratikjaiswa15)\
**Post date:** [February 12, 2020, 12:10pm UTC](https://forum.ionicframework.com/t/ionic-4-cant-perform-sha256-hashing-with-key-using-crypto-js/183184/1 "2020-02-12T12:10:40Z")

</div>

Hello, I am using crypto-js to perform sha256 hashing on data. The algorithm works fine without key like

```auto
CryptoJS.SHA256(message).toString(CryptoJS.enc.Hex)

```

But when I use a key for hashing it is generating wrong data.

Here is full code

```auto
import CryptoJS from 'crypto-js';

let key = 'the shared secret key here';
let message = 'the message to hash here';

console.log(message,key)

let ans = CryptoJS.SHA256(message,key).toString(CryptoJS.enc.Hex)
console.log(ans)

```

What I am doing wrong?  
Thank you in advance

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [February 12, 2020, 8:01pm UTC](https://forum.ionicframework.com/t/ionic-4-cant-perform-sha256-hashing-with-key-using-crypto-js/183184/2 "2020-02-12T20:01:22Z")

</div>

If you don’t get any better answers, I would use [WebCrypto](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) instead for this. I hope you’re not really hardcoding secrets into your app binary, though. Anybody can read them.
