Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicPythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcel

Node.js Examples


ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)

Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
VoiceBase
Walmart
WebSocket
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Node.js) Hash Binary Data (SHA256 and other hash algorithms)

Demonstrates how to hash binary bytes using SHA256, SHA384, SHA512, MD2, MD5, HAVAL, RIPEMD, etc.

Install Chilkat for Node.js using npm at

Chilkat npm packages for Node.js and Electron
on Windows, Linux, MacOSX, and ARM

Supports Node.js 4.*, 5.*, 6.*, 7.*, 8.*, and Electron 1.6.* and 1.7.*

var os = require('os');
if (os.platform() == 'win32') {  
    var chilkat = require('chilkat_node6_win32'); 
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('chilkat_node6_arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('chilkat_node6_linux32');
    } else {
        var chilkat = require('chilkat_node6_linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('chilkat_node6_macosx');
}

function chilkatExample() {

    //  This example requires the Chilkat Crypt API to have been previously unlocked.
    //  See Unlock Chilkat Crypt for sample code.

    //  Let's load a binary file to get the bytes..
    var jpgData = new chilkat.BinData();
    var success = jpgData.LoadFile("qa_data/jpg/starfish.jpg");
    if (success !== true) {
        console.log("Failed to load file.");
        return;
    }

    jpgBytes = jpgData.GetBinary();

    var crypt = new chilkat.Crypt2();

    //  Choose the hash algorithm.
    //  Can be  "sha1", "sha256", "sha384", "sha512", "md2", "md5", "haval", "ripemd128", "ripemd160","ripemd256", or "ripemd320".
    crypt.HashAlgorithm = "sha256";

    hashBytes = crypt.HashBytes(jpgBytes);

    //  Let's examine the hash as a hex string.
    var sb = new chilkat.StringBuilder();
    sb.AppendEncoded(hashBytes,"hex");
    console.log("SHA256 hash = " + sb.GetAsString());

    //  We could alternatively hash the bytes and receive the hex result directly:
    crypt.EncodingMode = "hex";
    var hashHexStr = crypt.HashBytesENC(jpgBytes);
    console.log("SHA256 hash = " + hashHexStr);

}

chilkatExample();

 

© 2000-2016 Chilkat Software, Inc. All Rights Reserved.