shib71 / mod-auth-token

Automatically exported from code.google.com/p/mod-auth-token
Apache License 2.0
0 stars 1 forks source link

URI generation in java #33

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
String secret="secret string";                    // Same as AuthTokenSecret
String protectedPath="/vod/";                   // Same as AuthTokenPrefix
//boolean ipLimitation=false;                     // Same as AuthTokenLimitByIp
long time= (new Date()).getTime();                // Time in decimal
time=time/1000;                                   // timestamp of java is 
longer than PHP 
String hexTime =Long.toHexString(time);            // hexTime  in Hexadecimal  
String token =getMD5( (secret+ filePathName + hexTime).getBytes());
return protectedPath +token+"/"+hexTime+ filePathName;

public String getMD5(byte[] source) {
    String s = null;
    char hexDigits[] = { 
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',   'e', 'f' };
    try {
        java.security.MessageDigest md = java.security.MessageDigest
                .getInstance("MD5");
        md.update(source);
        byte tmp[] = md.digest();
        char str[] = new char[16 * 2];
        int k = 0; 
        for (int i = 0; i < 16; i++) { 
            byte byte0 = tmp[i]; 
            str[k++] = hexDigits[byte0 >>> 4 & 0xf]; 
            str[k++] = hexDigits[byte0 & 0xf];
        }
        s = new String(str); 
    } catch (Exception e) {
        e.printStackTrace();
    }
    return s;
}

Original issue reported on code.google.com by kanchang...@gmail.com on 21 May 2012 at 4:17

GoogleCodeExporter commented 8 years ago
Added on main page.
Thanks.

Original comment by teixeira...@gmail.com on 24 May 2012 at 6:51