Possible issue running Keyczar sample

66 views
Skip to first unread message

Yolian Ignatov

unread,
Jan 24, 2014, 6:51:32 PM1/24/14
to keyczar...@googlegroups.com

I’m just getting my feet wet with Keyczar - looks like a great lib - going through the "Walkthrough and Sample Data” section the end of the "Keyczar: A Cryptographic Toolkit” PDF doc.

I’ve created an HMAC Keyset (8.1), generated an HMAC key (8.2), promoted the key (8.3) and am trying 8.5 Signing and Verifying in a java project I set up for this purpose which has the required dependences - log4j & gson.

However, initializing the Signer with the path to the keyset folder fails when trying to create a KeyMetadata object from a, seemingly valid JSON string, the KeyMetadata#read()#read() method:

   KeyMetadata kmd = Util.gson().fromJson(jsonString, KeyMetadata.class);

fails further down the call stack, specifically: 

SignatureParser.current() line: 95 [local variables unavailable]

with ArrayIndexOutOfBoundsException.

It's a rather simple sample... has anyone gone through it lately? Any idea what might be missing on my side?


Thanks,

Yolian

Evan Jones

unread,
Jan 27, 2014, 12:14:02 PM1/27/14
to keyczar...@googlegroups.com
I haven't gone through the example, but I can assure you that it is possible to get Keyczar to work. Here is a completely self-contained Java program that runs for me. I hope this helps?

Evan



import java.io.File;

import org.keyczar.KeyczarTool;
import org.keyczar.Signer;
import org.keyczar.exceptions.KeyczarException;

public class KeyczarExample {
public static void main(String[] arguments) throws KeyczarException {
final String KEY_PATH = "example_key";
final String EXAMPLE_INPUT = "example input";

File f = new File(KEY_PATH);
f.mkdir();

KeyczarTool.main(new String[]{"create", "--location=" + KEY_PATH, "--purpose=sign"});
KeyczarTool.main(new String[]{"addkey", "--location=" + KEY_PATH, "--status=primary"});
Signer signer = new Signer(KEY_PATH);

System.out.println("Input: " + EXAMPLE_INPUT);
String signature = signer.sign(EXAMPLE_INPUT);
System.out.println("Signature: " + signature);
System.out.println("Verified? " + signer.verify(signature, signature));
}
}



Output:

Input: example input
Signature: APXqm-QV30UMdKtVRHti9NgGmvr_RN_PGA
Verified? false


This creates a key in the directory "example_key"

--
Work: https://www.mitro.co/ Personal: http://evanjones.ca/

Reply all
Reply to author
Forward
0 new messages