Java Question Chilkat Rsa Library

Sytek

Active Member
Licensed User
Longtime User
Hello I'd created a library from the source code attached in the zip file.
....I can't call the library; But appears in the referenced libraries without the version info.
I don't know where to put the version info.
But I edit the chilkat.java and put the following

package com.chilkatsoft;

import anywheresoftware.b4a.BA;
//import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@Version(1.0f)
@ShortName("chilkatsoft")
//@ActivityObject
//@Author("chilkatsoft")


............
..And the version does not appear thank's for helping me (I need this library 'cause I need to sign a variable/file in SHA-1 format) as follows

B4X:
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {
  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView tv = new TextView(this);
    String outStr = "";

    CkPrivateKey pkey = new CkPrivateKey();

    //  Load the private key from an RSA PEM file:
    pkey.LoadPkcs8EncryptedFile("raul_privateKey.key","a0123456789");

    boolean success;

    String pkeyXml;
    //  Get the private key in XML format:
    pkeyXml = pkey.getXml();

    CkRsa rsa = new CkRsa();

    //  Any string argument automatically begins the 30-day trial.

    success = rsa.UnlockComponent("Anything for 30-day trial.");
    if (success != true) {
        outStr += "RSA component unlock failed" + "\n";
        tv.setText(outStr);
        setContentView(tv);
        return;
    }

    //  Import the private key into the RSA component:
    success = rsa.ImportPrivateKey(pkeyXml);
    if (success != true) {
        outStr += rsa.lastErrorText() + "\n";
        tv.setText(outStr);
        setContentView(tv);
        return;
    }

    //  This example will sign a string, and receive the signature
    //  in a hex-encoded string.  Therefore, set the encoding mode
    //  to "hex":
    rsa.put_EncodingMode("hex");

    String strData;
    strData = "This is the string to be signed.";

    //  Sign the string using the sha-1 hash algorithm.
    //  Other valid choices are "md2" and "md5".
    String hexSig;
    hexSig = rsa.signStringENC(strData,"sha-1");

    outStr += hexSig + "\n";

    //  Now verify with the public key.
    //  This example shows how to use the public key from
    //  a digital certificate (.cer file)
    CkCert cert = new CkCert();
    success = cert.LoadFromFile("raul_publicKey.cer");
    if (success != true) {
        outStr += cert.lastErrorText() + "\n";
        tv.setText(outStr);
        setContentView(tv);
        return;
    }

    CkPublicKey pubKey;
    pubKey = cert.ExportPublicKey();

    String pubKeyXml;
    //  Get the private key in XML format:
    pubKeyXml = pubKey.getXml();

    CkRsa rsa2 = new CkRsa();
    success = rsa2.ImportPublicKey(pubKeyXml);
    if (success != true) {
        outStr += rsa2.lastErrorText() + "\n";
        tv.setText(outStr);
        setContentView(tv);
        return;
    }

    //  Verify the signature against the original data:
    rsa2.put_EncodingMode("hex");
    success = rsa2.VerifyStringENC(strData,"sha-1",hexSig);
    if (success != true) {
        outStr += rsa2.lastErrorText() + "\n";
        tv.setText(outStr);
        setContentView(tv);
        return;
    }

    outStr += "Signature verified!" + "\n";

    //  Verify with incorrect data:
    success = rsa2.VerifyStringENC("something else","sha-1",hexSig);
    if (success != true) {
        outStr +=  + "\n";    }

    tv.setText(outStr);
    setContentView(tv);
  }

  static {
      // Important: Make sure the name passed to loadLibrary matches the shared library
      // found in your project's libs/armeabi directory.
      //  for "libchilkat.so", pass "chilkat" to loadLibrary
      //  for "libchilkatemail.so", pass "chilkatemail" to loadLibrary
      //  etc.
      //
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Referenced libraries without the version info.
upload_2014-2-21_1-7-32-png.22912


Best Regards!

Original Source Code: http://www.chilkatsoft.com/download/chilkat-9.4.1-android-rsa.zip
 

Attachments

  • chilkat-9.4.1-android-rsa.zip
    22.8 KB · Views: 433

Sytek

Active Member
Licensed User
Longtime User
Thank's Erel, That one works, now I will check how the oncreate works.

...I need to call this one
B4X:
CkPrivateKey pkey = new CkPrivateKey();
    //  Load the private key from an RSA PEM file:
    pkey.LoadPkcs8EncryptedFile("raul_privateKey.key","a0123456789");

...From this one.

B4X:
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView tv = new TextView(this);
    String outStr = "";

    CkPrivateKey pkey = new CkPrivateKey();

    //  Load the private key from an RSA PEM file:
    pkey.LoadPkcs8EncryptedFile("raul_privateKey.key","a0123456789");

Best Regards!
 
Top