1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| package ;
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[])
{
CkRsa rsa = new CkRsa();
boolean success;
success = rsa.UnlockComponent("Anything for 30-day trial");
if (success != true) {
System.out.println("RSA component unlock failed");
return;
}
// Generate a 1024-bit key. Chilkat RSA supports
// key sizes ranging from 512 bits to 4096 bits.
success = rsa.GenerateKey(1024);
if (success != true) {
System.out.println(rsa.lastErrorText());
return;
}
// Keys are exported in XML format:
String publicKey;
publicKey = rsa.exportPublicKey();
System.out.println(publicKey);
String privateKey;
privateKey = rsa.exportPrivateKey();
System.out.println(privateKey);
}
} |
Partager