Example usage for org.bouncycastle.crypto.macs CMac reset

List of usage examples for org.bouncycastle.crypto.macs CMac reset

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.macs CMac reset.

Prototype

public void reset() 

Source Link

Document

Reset the mac generator.

Usage

From source file:com.pearson.pdn.learningstudio.helloworld.OAuth1SignatureServlet.java

License:Apache License

private String generateCmac(String key, String msg) throws UnsupportedEncodingException {
    byte[] keyBytes = key.getBytes("UTF-8");
    byte[] data = msg.getBytes("UTF-8");

    CMac macProvider = new CMac(new AESFastEngine());
    macProvider.init(new KeyParameter(keyBytes));
    macProvider.reset();

    macProvider.update(data, 0, data.length);
    byte[] output = new byte[macProvider.getMacSize()];
    macProvider.doFinal(output, 0);/*from   w w  w  .  j a v a2  s .c  o  m*/

    // Convert the CMAC to a Base64 string and remove the new line the
    // Base64 library adds
    String cmac = Base64.encodeBase64String(output).replaceAll("\r\n", "");

    return cmac;
}

From source file:com.pearson.pdn.learningstudio.helloworld.OAuth2AssertionServlet.java

License:Apache License

private String generateCmac(String key, String msg) throws UnsupportedEncodingException {
    byte[] keyBytes = key.getBytes("UTF-8");
    byte[] data = msg.getBytes("UTF-8");

    CMac macProvider = new CMac(new AESFastEngine());
    macProvider.init(new KeyParameter(keyBytes));
    macProvider.reset();

    macProvider.update(data, 0, data.length);
    byte[] output = new byte[macProvider.getMacSize()];
    macProvider.doFinal(output, 0);//from  w  w  w  .j  ava2 s. c  om

    return Strings.fromUTF8ByteArray(Hex.encode(output));
}

From source file:com.pearson.pdn.learningstudio.oauth.OAuth1SignatureService.java

License:Apache License

/**
 * Generates a Base64-encoded CMAC-AES digest
 * //w  w  w.j  a  va2  s  .c o  m
 * @param key
 *            The secret key used to sign the data
 * @param msg
 *            The data to be signed
 * 
 * @return A CMAC-AES hash
 * 
 * @throws UnsupportedEncodingException
 */
private String generateCmac(String key, String msg) throws UnsupportedEncodingException {
    byte[] keyBytes = key.getBytes("UTF-8");
    byte[] data = msg.getBytes("UTF-8");

    CMac macProvider = new CMac(new AESFastEngine());
    macProvider.init(new KeyParameter(keyBytes));
    macProvider.reset();

    macProvider.update(data, 0, data.length);
    byte[] output = new byte[macProvider.getMacSize()];
    macProvider.doFinal(output, 0);

    // Convert the CMAC to a Base64 string and remove the new line the
    // Base64 library adds
    String cmac = Base64.encodeBase64String(output).replaceAll("\r\n", "");

    return cmac;
}

From source file:com.pearson.pdn.learningstudio.oauth.OAuth2AssertionService.java

License:Apache License

/**
 * Generates a HEX-encoded CMAC-AES digest
 * /*from w ww. j a v  a 2  s. co m*/
 * @param key
 *            The secret key used to sign the data
 * @param msg
 *            The data to be signed
 * 
 * @return A CMAC-AES digest
 * 
 * @throws UnsupportedEncodingException
 */
private String generateCmac(String key, String msg) throws UnsupportedEncodingException {
    byte[] keyBytes = key.getBytes("UTF-8");
    byte[] data = msg.getBytes("UTF-8");

    CMac macProvider = new CMac(new AESFastEngine());
    macProvider.init(new KeyParameter(keyBytes));
    macProvider.reset();

    macProvider.update(data, 0, data.length);
    byte[] output = new byte[macProvider.getMacSize()];
    macProvider.doFinal(output, 0);

    return Strings.fromUTF8ByteArray(Hex.encode(output));
}

From source file:org.crypto.sse.CryptoPrimitives.java

License:Open Source License

public static byte[] generateCmac(byte[] key, String msg) throws UnsupportedEncodingException {
    CMac cmac = new CMac(new AESFastEngine());
    byte[] data = msg.getBytes("UTF-8");
    byte[] output = new byte[cmac.getMacSize()];

    cmac.init(new KeyParameter(key));
    cmac.reset();
    cmac.update(data, 0, data.length);//from   w  ww . j  a  va  2  s  .c  o  m
    cmac.doFinal(output, 0);
    return output;
}