login about faq

I have a working hashing task in VB.NET as follows:

    Dim operand As Byte() = some bytes....
    Dim ckCrypt As New Chilkat.Crypt2()
    ckCrypt.EncodingMode = "Base64"
    ckCrypt.HashAlgorithm = "sha1"
    Dim lNewDigest As String = ckCrypt.HashBytesENC(operand)

This works perfectly. The variable lNewDigest gets the Digest value as expected.

Now I have a need to have the same task in Android.

So my code is:

    byte[] operand= some bytes....
    CkCrypt2 ckCrypt = new CkCrypt2();
    ckCrypt.put_EncodingMode( "Base64");
    ckCrypt.put_HashAlgorithm ( "sha1");
    String lNewDigest = ckCrypt.HashBytesENC(operand);

I saw some example on using CkByteData in between. But I am totally lost. I did not have any luck in appending plain bytes (operand) to CkByteData.

asked Dec 21 '16 at 12:33

chilkat's gravatar image

chilkat ♦♦

I completely understand why you are lost -- it's entirely confusing and there are plans for the future to rid ourselves of needing to use CkByteData (and CkString)..

For now though, here's the solution:

CkCrypt2 crypt = new CkCrypt2();

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

CkByteData byteData = new CkByteData(); byte[] myData = "Any String you want".getBytes(); byteData.appendByteArray(myData);

String sha1Hash = crypt.hashBytesENC(byteData); System.out.println(sha1Hash);


answered Dec 21 '16 at 12:35

chilkat's gravatar image

chilkat ♦♦

edited Dec 21 '16 at 12:36

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Dec 21 '16 at 12:33

Seen: 759 times

Last updated: Dec 21 '16 at 12:36

powered by OSQA