Last active
August 29, 2015 14:07
-
-
Save yokolet/53a5c0ed646c26eaeb8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KS = Java::JavaxCryptoSpec::SecretKeySpec | |
MAC = Java::JavaxCrypto::Mac | |
ENCODER = Java::SunMisc::BASE64Encoder | |
seed = "66fbcbf2-74b8-46bf-bf8a-fe925efaaa18-Tue Oct 07 09:04:49 EDT 2014" | |
secret_key = SKS.new(seed.to_java_bytes, "HmacSHA256") | |
msg = "[12345]".to_java_bytes | |
buf = Java::JavaIo::ByteArrayOutputStream.new | |
buf.write(msg, 0, msg.length) | |
mac = MAC.getInstance("HmacSHA256") | |
mac.init(secret_key) | |
bbuf = Java::JavaNio::ByteBuffer.wrap(buf.toByteArray) | |
result = bbuf.duplicate | |
mac.update(result) | |
hmac = mac.doFinal | |
encoder = ENCODER.new | |
puts encoder.encode(hmac) | |
## 8110nQFYfylC27BjDRZbq5S06+/s4ewnFoJKbmK5D44= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment