Example usage for org.bouncycastle.util Strings fromUTF8ByteArray

List of usage examples for org.bouncycastle.util Strings fromUTF8ByteArray

Introduction

In this page you can find the example usage for org.bouncycastle.util Strings fromUTF8ByteArray.

Prototype

public static String fromUTF8ByteArray(byte[] bytes) 

Source Link

Usage

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();//w  w  w  .  j  a  va 2s  . c om

    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:com.pearson.pdn.learningstudio.oauth.OAuth2AssertionService.java

License:Apache License

/**
 * Generates a HEX-encoded CMAC-AES digest
 * //from w w  w  . j  a  v a2 s. com
 * @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:de.afarber.tlspskserver.MockPSKTlsServer.java

License:Open Source License

@Override
public void notifyHandshakeComplete() throws IOException {
    super.notifyHandshakeComplete();

    byte[] pskIdentity = context.getSecurityParameters().getPSKIdentity();
    if (pskIdentity != null) {
        String name = Strings.fromUTF8ByteArray(pskIdentity);
        System.out.println("TLS-PSK server completed handshake for PSK identity: " + name);
    }//  w  w w . j a  v a2 s .  co  m
}

From source file:org.activityinfo.server.login.ViewTestCase.java

License:Open Source License

protected String process(PageModel model) throws IOException, TemplateException {
    FreemarkerViewProcessor processor = new FreemarkerViewProcessor(templateCfg, Providers.of(Locale.ENGLISH),
            new ScaffoldingDirective(Providers.of(Domain.DEFAULT), templateCfg));
    Template template = processor.resolve(model.asViewable().getTemplateName());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    processor.writeTo(template, model.asViewable(), baos);

    return Strings.fromUTF8ByteArray(baos.toByteArray());
}

From source file:org.sufficientlysecure.keychain.linked.UriAttribute.java

License:Open Source License

static UriAttribute fromSubpacketData(byte[] data) {

    try {/*w w  w.  j  a va2  s  .co m*/
        String uriStr = Strings.fromUTF8ByteArray(data);
        URI uri = URI.create(uriStr);

        LinkedResource res = LinkedTokenResource.fromUri(uri);
        if (res == null) {
            return new UriAttribute(uri);
        }

        return new LinkedAttribute(uri, res);

    } catch (IllegalArgumentException e) {
        Log.e(Constants.TAG, "error parsing uri in (suspected) linked id packet");
        return null;
    }
}