Home Reference Source Test
public class | source

Sha256

Extends:

src/hasher/hasher32be.js~Hasher32be → Sha256

Calculates SHA256 (SHA224) hash

Example:

Calculates SHA256 hash from string "message" - ES6 style
import Sha256 from "crypto-api/src/hasher/sha256";
import {toHex} from "crypto-api/src/encoder/hex";

let hasher = new Sha256();
hasher.update('message');
console.log(toHex(hasher.finalize()));
Calculates SHA256 hash from UTF string "message" - ES6 style
import Sha256 from "crypto-api/src/hasher/sha256";
import {toHex} from "crypto-api/src/encoder/hex";
import {fromUtf} from "crypto-api/src/encoder/utf";

let hasher = new Sha256();
hasher.update(fromUtf('message'));
console.log(toHex(hasher.finalize()));
Calculates SHA256 hash from string "message" - ES5 style
<script src="https://nf404.github.io/crypto-api/crypto-api.min.js"></script>
<script>
  var hasher = CryptoApi.getHasher('sha256');
  hasher.update('message');
  console.log(CryptoApi.encoder.toHex(hasher.finalize()));
</script>
Calculates SHA256 hash from UTF string "message" - ES5 style
<script src="https://nf404.github.io/crypto-api/crypto-api.min.js"></script>
<script>
  console.log(CryptoApi.hash('sha256', 'message'));
</script>

Test:

Constructor Summary

Public Constructor
public

constructor(options: Object)

Method Summary

Public Methods
public

finalize(): string

Finalize hash and return result

public

reset()

Reset hasher to initial state

Public Constructors

public constructor(options: Object) source

Params:

NameTypeAttributeDescription
options Object
  • optional
options.rounds number
  • optional
  • default: 64

Number of rounds (Must be greater than 16)

options.length number
  • optional
  • default: 256

Length of hash result

Hash type Length
sha224 224
sha256 256

Public Methods

public finalize(): string source

Finalize hash and return result

Return:

string

public reset() source

Reset hasher to initial state