阿里云IOT 用MQTT.fx 连接 生成用户密码

 swing 窗体小工具版本 https://blog.csdn.net/jintaocccq/article/details/108364751

 @Test
    public void re() throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
        String productKey = "";
        String deviceName = "";
        String deviceSecret = "";
        String clientId = UUID.randomUUID().toString().replace("-", "").toUpperCase();
        String region = "cn-shanghai";
        String data = "clientId" + clientId + "deviceName" + deviceName + "productKey" + productKey;

        System.out.println("address  : " + productKey + ".iot-as-mqtt." + region + ".aliyuncs.com");
        System.out.println("clientId : " + clientId + "|securemode=3,signmethod=hmacsha1|");
        System.out.println("userName : " + deviceName + "&" + productKey);
        System.out.println("passwd   : " + SignUtil.re(data, deviceSecret).toUpperCase());


    }

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.util.Formatter;

/**
 * @author ljt
 * @version 1.0
 * @date 2019/9/3 16:03
 */
public class SignUtil {
    private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
    private static String toHexString(byte[] bytes) {
        Formatter formatter = new Formatter();
        for (byte b : bytes) {
            formatter.format("%02x", b);
        }
        return formatter.toString();
    }

    public static String re(String data, String key) throws SignatureException, NoSuchAlgorithmException, InvalidKeyException, InvalidKeyException, NoSuchAlgorithmException {
        SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
        Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
        mac.init(signingKey);
        return toHexString(mac.doFinal(data.getBytes()));

    }

   
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值