Example usage for com.google.gwt.core.client JsArrayInteger setLength

List of usage examples for com.google.gwt.core.client JsArrayInteger setLength

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsArrayInteger setLength.

Prototype

public final native void setLength(int newLength) ;

Source Link

Document

Reset the length of the array.

Usage

From source file:org.cruxframework.crux.core.client.encoder.MD5.java

License:Apache License

/**
 * Calculate the HMAC-MD5, of a key and some data (raw strings)
 *///from  w w w.  j av  a 2  s  .c  om
public static String rawHmacMD5(String key, String data) {
    JsArrayInteger bkey = rstr2binl(key);
    if (bkey.length() > 16)
        bkey = binl2md5(bkey, key.length() * 8);

    JsArrayInteger ipad = JsArrayInteger.createArray().cast();
    JsArrayInteger opad = JsArrayInteger.createArray().cast();
    ipad.setLength(16);
    opad.setLength(16);
    for (int i = 0; i < 16; i++) {
        ipad.set(i, bkey.get(i) ^ 0x36363636);
        opad.set(i, bkey.get(i) ^ 0x5C5C5C5C);
    }

    JsArrayInteger hash = binl2md5(concat(ipad, rstr2binl(data)), 512 + data.length() * 8);
    return binl2rstr(binl2md5(concat(opad, hash), 512 + 128));
}