tags:

views:

181

answers:

2

Give a public key, I want to generate a public digest. Below is the code in JSP, but I need this in Ruby. I'm uncertain of the equivalents of SecretKeySpec, doFinal, etc. I'm using hmac, and hmac-sha1 on the Ruby end of things.

String pub = 'my_public_key';
BASE64Encoder encoder = new BASE64Encoder();
Mac sha1Mac = Mac.getInstance("HmacSHA1");
SecretKeySpec publicKeySpec = new SecretKeySpec(pub.getBytes(), "HmacSHA1");
sha1Mac.init(publicKeySpec);
byte[] publicBytes = sha1Mac.doFinal(subscriptionID.getBytes());
String publicDigest = encoder.encodeBuffer(publicBytes);
publicDigest = publicDigest.replaceAll("\n", "");
+1  A: 

Here is a page that should get you started.

By the way, I have some sympathy for J. Riggs' issue. While OpenSSL does ship as part of The Ruby Standard Library, it has no RDoc other than a mechanical listing of method names, and ri OpenSSL returns a grand total of three (3, count 'em) lines. . .

DigitalRoss
+1  A: 
sha1 = HMAC::SHA1.new( @public_key )
sha1 << data
Base64.encode64( sha1.digest )

Worked. Digests matched between the ruby and java examples.

J. Riggs