Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.annotation.SuppressLint;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static String getCallSignature(String subAccountSid, String subAccountToken) {
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        String timestamp = format.format(new Date());
        String signature = subAccountSid + subAccountToken + timestamp;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            return byte2HexStr(md.digest(signature.getBytes("utf-8")));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    private static String byte2HexStr(byte[] b) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < b.length; ++i) {
            String s = Integer.toHexString(b[i] & 0xFF);
            if (s.length() == 1)
                sb.append("0");

            sb.append(s.toUpperCase());
        }
        return sb.toString();
    }
}