Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

Workaround for the deprecated Crypt2.VerifyString method

Shows how to replace the deprecated VerifyString method. (Chilkat is moving away from the use of CkByteData.)

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkCrypt2 crypt = new CkCrypt2();

    //  Specifies how the original data bytes are converted to characters
    crypt.put_Charset("utf-8");

    String originalText = "this is the string that was signed.";
    String sigPath = "c:/someDir/example.p7s";

    //  ------------------------------------------------------------------------
    //  The OpaqueVerifyString method is deprecated:

    CkByteData detachedSigBytes = new CkByteData();
    detachedSigBytes.loadFile(sigPath);

    boolean verified = crypt.VerifyString(originalText,detachedSigBytes);

    //  ------------------------------------------------------------------------
    //  Workaround.
    //  (Chilkat is moving away from using CkByteData)

    CkBinData bdSig = new CkBinData();
    bdSig.LoadFile(sigPath);

    String encoding = "base64";
    crypt.put_EncodingMode(encoding);
    verified = crypt.VerifyStringENC(originalText,bdSig.getEncoded(encoding));
  }
}