Example usage for org.bouncycastle.crypto.macs HMac getAlgorithmName

List of usage examples for org.bouncycastle.crypto.macs HMac getAlgorithmName

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.macs HMac getAlgorithmName.

Prototype

public String getAlgorithmName() 

Source Link

Usage

From source file:net.oauth.j2me.signature.HMACSHA1Signature.java

License:Apache License

public String getSignature() {
    try {/*from   w  w w .j  a  va  2 s .  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;
}