package com.miaxis.common.sign;




import java.security.KeyStore;
import java.security.PrivateKey;
import java.util.Enumeration;

/**
 */
public class SignUtil {
	public static String getSign(byte[] data)throws Exception{
        String sign_str = ""; // 签名
		KeyStore keyStore = KeyStore.getInstance("PKCS12");
		Enumeration<String> aliases = keyStore.aliases();
		if (!aliases.hasMoreElements()) { ;
			throw new RuntimeException("HTTP接口协议签名获取失败: no alias found");
		}
		String alias = aliases.nextElement();
		PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, PlatUtil.keyPassword.toCharArray()); // 私钥
		ISign sign = new Sign();
        long timestamp = System.currentTimeMillis(); // 时间戳
        sign_str = sign.sign(data,timestamp , privateKey);
        return sign_str;
	}
}
