List of usage examples for org.bouncycastle.crypto.macs HMac getUnderlyingDigest
public Digest getUnderlyingDigest()
From source file:com.joyent.manta.client.crypto.SupportedHmacsLookupMap.java
License:Open Source License
/** * Finds the HMAC implementation name based on the passed object. * * @param hmac instance to find name for * @return the name of implementation used by the SDK *//*from w w w . j a va 2 s . c o m*/ public static String hmacNameFromInstance(final HMac hmac) { Validate.notNull(hmac, "HMAC instance must not be null"); final String digestName = hmac.getUnderlyingDigest().getAlgorithmName(); return "Hmac" + StringUtils.strip(digestName, "-"); }
From source file:com.joyent.manta.serialization.HmacSerializer.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public void write(final Kryo kryo, final Output output, final HMac object) { final EncodableDigest ipadState = (EncodableDigest) readField(ipadStateField, object); final EncodableDigest opadState = (EncodableDigest) readField(opadStateField, object); final EncodableDigest digest = (EncodableDigest) object.getUnderlyingDigest(); kryo.writeObject(output, digest.getClass()); output.writeInt(digest.getEncodedState().length); output.write(digest.getEncodedState()); output.writeInt(ipadState.getEncodedState().length); output.write(ipadState.getEncodedState()); output.writeInt(opadState.getEncodedState().length); output.write(opadState.getEncodedState()); output.flush();// ww w . j a v a 2 s . c om }
From source file:com.joyent.manta.util.HmacCloner.java
License:Open Source License
@Override public HMac createClone(final HMac source) { final Digest originalDigest = source.getUnderlyingDigest(); final Digest clonedDigest = new DigestCloner().createClone(originalDigest); final HMac cloned = new HMac(clonedDigest); try {//from ww w .j a v a2 s . c o m final Memoable ipadState = (Memoable) readField(FIELD_IPAD_STATE, source, true); final Memoable opadState = (Memoable) readField(FIELD_OPAD_STATE, source, true); writeField(FIELD_IPAD_STATE, cloned, ipadState.copy()); writeField(FIELD_OPAD_STATE, cloned, opadState.copy()); } catch (IllegalAccessException e) { throw new MantaReflectionException(e); } return cloned; }
From source file:net.oauth.j2me.signature.HMACSHA1Signature.java
License:Apache License
public String getSignature() { try {/*from w w w . ja v a 2s. c o m*/ HMac m = new HMac(new SHA1Digest()); m.init(new KeyParameter(key.getBytes("UTF-8"))); byte[] bytes = message.getBytes("UTF-8"); m.update(bytes, 0, bytes.length); byte[] mac = new byte[m.getMacSize()]; m.doFinal(mac, 0); signature = new String(Util.base64Encode(mac)); // debug System.out.println("mac alg: " + m.getAlgorithmName()); System.out.println("dig alg: " + m.getUnderlyingDigest().getAlgorithmName()); System.out.println("key: " + key); System.out.println("message: " + message); System.out.println("unencoded: " + new String(mac)); System.out.println("sig: " + signature); } catch (java.io.UnsupportedEncodingException e) { ; } catch (Exception e) { ; } return signature; }