使用MQTT连接阿里云时键入证书的问题

文章介绍了在使用MQTT协议与阿里云进行动态注册时遇到的证书输入问题,特别是当在C或C++程序中处理证书字符串时。提供了一种将证书转换为十六进制数组的方法,以确保100%成功连接,这种方法虽然直观但非常实用。
摘要由CSDN通过智能技术生成

使用MQTT连接阿里云时键入证书的问题

前言

使用阿里云进行动态注册时,大家都会遇到键入证书的问题,当使用串口调试助手进行证书的键入时,一般不会有问题,但是如果在程序中进行证书的字符串拼接时,无论是C语言还是C++都会遇到很多问题,导致键入失败,下面给大家介绍一种方法可以保证百分之百成功,虽然有点笨但是好用,也省去了大家解决问题的时间。


键入证书解决方法

我在这里直接使用了该证书的十六进制数组,经验证完全没问题,省得大家自己去输入数组的时间。

下面首先是需要键入的证书字符串

-----BEGIN CERTIFICATE-----
MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG
A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv
b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw
MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i
YWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYDVQQDExJHbG9iYWxT
aWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDaDuaZ
jc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavp
xy0Sy6scTHAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp
1Wrjsok6Vjk4bwY8iGlbKk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdG
snUOhugZitVtbNV4FpWi6cgKOOvyJBNPc1STE4U6G7weNLWLBYy5d4ux2x8gkasJ
U26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrXgzT/LCrBbBlDSgeF59N8
9iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8E
BTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0B
AQUFAAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOz
yj1hTdNGCbM+w6DjY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE
38NflNUVyRRBnMRddWQVDf9VMOyGj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymP
AbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhHhm4qxFYxldBniYUr+WymXUad
DKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveCX4XSQRjbgbME
HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A== -----END CERTIFICATE-----

接下来是我将字符串转为十六进制的数组,大家直接复制拿去用(虽然看着不咋地但是真的好用):

/* CA证书数组 */
uint8_t Cert[] = {0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46,
0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A, 0x4D, 0x49, 0x49, 0x44, 0x64, 0x54, 0x43, 0x43, 0x41,
0x6C, 0x32, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x4C, 0x42, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42, 0x46,
0x55, 0x74, 0x61, 0x77, 0x35, 0x51, 0x77, 0x44, 0x51, 0x59, 0x4A, 0x4B, 0x6F, 0x5A, 0x49, 0x68, 0x76, 0x63, 0x4E, 0x41,
0x51, 0x45, 0x46, 0x42, 0x51, 0x41, 0x77, 0x56, 0x7A, 0x45, 0x4C, 0x4D, 0x41, 0x6B, 0x47, 0x0A, 0x41, 0x31, 0x55, 0x45,
0x42, 0x68, 0x4D, 0x43, 0x51, 0x6B, 0x55, 0x78, 0x47, 0x54, 0x41, 0x58, 0x42, 0x67, 0x4E, 0x56, 0x42, 0x41, 0x6F, 0x54,
0x45, 0x45, 0x64, 0x73, 0x62, 0x32, 0x4A, 0x68, 0x62, 0x46, 0x4E, 0x70, 0x5A, 0x32, 0x34, 0x67, 0x62, 0x6E, 0x59, 0x74,
0x63, 0x32, 0x45, 0x78, 0x45, 0x44, 0x41, 0x4F, 0x42, 0x67, 0x4E, 0x56, 0x42, 0x41, 0x73, 0x54, 0x42, 0x31, 0x4A, 0x76,
0x0A, 0x62, 0x33, 0x51, 0x67, 0x51, 0x30, 0x45, 0x78, 0x47, 0x7A, 0x41, 0x5A, 0x42, 0x67, 0x4E, 0x56, 0x42, 0x41, 0x4D,
0x54, 0x45, 0x6B, 0x64, 0x73, 0x62, 0x32, 0x4A, 0x68, 0x62, 0x46, 0x4E, 0x70, 0x5A, 0x32, 0x34, 0x67, 0x55, 0x6D, 0x39,
0x76, 0x64, 0x43, 0x42, 0x44, 0x51, 0x54, 0x41, 0x65, 0x46, 0x77, 0x30, 0x35, 0x4F, 0x44, 0x41, 0x35, 0x4D, 0x44, 0x45,
0x78, 0x4D, 0x6A, 0x41, 0x77, 0x0A, 0x4D, 0x44, 0x42, 0x61, 0x46, 0x77, 0x30, 0x79, 0x4F, 0x44, 0x41, 0x78, 0x4D, 0x6A,
0x67, 0x78, 0x4D, 0x6A, 0x41, 0x77, 0x4D, 0x44, 0x42, 0x61, 0x4D, 0x46, 0x63, 0x78, 0x43, 0x7A, 0x41, 0x4A, 0x42, 0x67,
0x4E, 0x56, 0x42, 0x41, 0x59, 0x54, 0x41, 0x6B, 0x4A, 0x46, 0x4D, 0x52, 0x6B, 0x77, 0x46, 0x77, 0x59, 0x44, 0x56, 0x51,
0x51, 0x4B, 0x45, 0x78, 0x42, 0x48, 0x62, 0x47, 0x39, 0x69, 0x0A, 0x59, 0x57, 0x78, 0x54, 0x61, 0x57, 0x64, 0x75, 0x49,
0x47, 0x35, 0x32, 0x4C, 0x58, 0x4E, 0x68, 0x4D, 0x52, 0x41, 0x77, 0x44, 0x67, 0x59, 0x44, 0x56, 0x51, 0x51, 0x4C, 0x45,
0x77, 0x64, 0x53, 0x62, 0x32, 0x39, 0x30, 0x49, 0x45, 0x4E, 0x42, 0x4D, 0x52, 0x73, 0x77, 0x47, 0x51, 0x59, 0x44, 0x56,
0x51, 0x51, 0x44, 0x45, 0x78, 0x4A, 0x48, 0x62, 0x47, 0x39, 0x69, 0x59, 0x57, 0x78, 0x54, 0x0A, 0x61, 0x57, 0x64, 0x75,
0x49, 0x46, 0x4A, 0x76, 0x62, 0x33, 0x51, 0x67, 0x51, 0x30, 0x45, 0x77, 0x67, 0x67, 0x45, 0x69, 0x4D, 0x41, 0x30, 0x47,
0x43, 0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33, 0x44, 0x51, 0x45, 0x42, 0x41, 0x51, 0x55, 0x41, 0x41, 0x34, 0x49, 0x42,
0x44, 0x77, 0x41, 0x77, 0x67, 0x67, 0x45, 0x4B, 0x41, 0x6F, 0x49, 0x42, 0x41, 0x51, 0x44, 0x61, 0x44, 0x75, 0x61, 0x5A,
0x0A, 0x6A, 0x63, 0x36, 0x6A, 0x34, 0x30, 0x2B, 0x4B, 0x66, 0x76, 0x76, 0x78, 0x69, 0x34, 0x4D, 0x6C, 0x61, 0x2B, 0x70,
0x49, 0x48, 0x2F, 0x45, 0x71, 0x73, 0x4C, 0x6D, 0x56, 0x45, 0x51, 0x53, 0x39, 0x38, 0x47, 0x50, 0x52, 0x34, 0x6D, 0x64,
0x6D, 0x7A, 0x78, 0x7A, 0x64, 0x7A, 0x78, 0x74, 0x49, 0x4B, 0x2B, 0x36, 0x4E, 0x69, 0x59, 0x36, 0x61, 0x72, 0x79, 0x6D,
0x41, 0x5A, 0x61, 0x76, 0x70, 0x0A, 0x78, 0x79, 0x30, 0x53, 0x79, 0x36, 0x73, 0x63, 0x54, 0x48, 0x41, 0x48, 0x6F, 0x54,
0x30, 0x4B, 0x4D, 0x4D, 0x30, 0x56, 0x6A, 0x55, 0x2F, 0x34, 0x33, 0x64, 0x53, 0x4D, 0x55, 0x42, 0x55, 0x63, 0x37, 0x31,
0x44, 0x75, 0x78, 0x43, 0x37, 0x33, 0x2F, 0x4F, 0x6C, 0x53, 0x38, 0x70, 0x46, 0x39, 0x34, 0x47, 0x33, 0x56, 0x4E, 0x54,
0x43, 0x4F, 0x58, 0x6B, 0x4E, 0x7A, 0x38, 0x6B, 0x48, 0x70, 0x0A, 0x31, 0x57, 0x72, 0x6A, 0x73, 0x6F, 0x6B, 0x36, 0x56,
0x6A, 0x6B, 0x34, 0x62, 0x77, 0x59, 0x38, 0x69, 0x47, 0x6C, 0x62, 0x4B, 0x6B, 0x33, 0x46, 0x70, 0x31, 0x53, 0x34, 0x62,
0x49, 0x6E, 0x4D, 0x6D, 0x2F, 0x6B, 0x38, 0x79, 0x75, 0x58, 0x39, 0x69, 0x66, 0x55, 0x53, 0x50, 0x4A, 0x4A, 0x34, 0x6C,
0x74, 0x62, 0x63, 0x64, 0x47, 0x36, 0x54, 0x52, 0x47, 0x48, 0x52, 0x6A, 0x63, 0x64, 0x47, 0x0A, 0x73, 0x6E, 0x55, 0x4F,
0x68, 0x75, 0x67, 0x5A, 0x69, 0x74, 0x56, 0x74, 0x62, 0x4E, 0x56, 0x34, 0x46, 0x70, 0x57, 0x69, 0x36, 0x63, 0x67, 0x4B,
0x4F, 0x4F, 0x76, 0x79, 0x4A, 0x42, 0x4E, 0x50, 0x63, 0x31, 0x53, 0x54, 0x45, 0x34, 0x55, 0x36, 0x47, 0x37, 0x77, 0x65, 
0x4E, 0x4C, 0x57, 0x4C, 0x42, 0x59, 0x79, 0x35, 0x64, 0x34, 0x75, 0x78, 0x32, 0x78, 0x38, 0x67, 0x6B, 0x61, 0x73, 0x4A,
0x0A, 0x55, 0x32, 0x36, 0x51, 0x7A, 0x6E, 0x73, 0x33, 0x64, 0x4C, 0x6C, 0x77, 0x52, 0x35, 0x45, 0x69, 0x55, 0x57, 0x4D,
0x57, 0x65, 0x61, 0x36, 0x78, 0x72, 0x6B, 0x45, 0x6D, 0x43, 0x4D, 0x67, 0x5A, 0x4B, 0x39, 0x46, 0x47, 0x71, 0x6B, 0x6A,
0x57, 0x5A, 0x43, 0x72, 0x58, 0x67, 0x7A, 0x54, 0x2F, 0x4C, 0x43, 0x72, 0x42, 0x62, 0x42, 0x6C, 0x44, 0x53, 0x67, 0x65,
0x46, 0x35, 0x39, 0x4E, 0x38, 0x0A, 0x39, 0x69, 0x46, 0x6F, 0x37, 0x2B, 0x72, 0x79, 0x55, 0x70, 0x39, 0x2F, 0x6B, 0x35,
0x44, 0x50, 0x41, 0x67, 0x4D, 0x42, 0x41, 0x41, 0x47, 0x6A, 0x51, 0x6A, 0x42, 0x41, 0x4D, 0x41, 0x34, 0x47, 0x41, 0x31,
0x55, 0x64, 0x44, 0x77, 0x45, 0x42, 0x2F, 0x77, 0x51, 0x45, 0x41, 0x77, 0x49, 0x42, 0x42, 0x6A, 0x41, 0x50, 0x42, 0x67,
0x4E, 0x56, 0x48, 0x52, 0x4D, 0x42, 0x41, 0x66, 0x38, 0x45, 0x0A, 0x42, 0x54, 0x41, 0x44, 0x41, 0x51, 0x48, 0x2F, 0x4D,
0x42, 0x30, 0x47, 0x41, 0x31, 0x55, 0x64, 0x44, 0x67, 0x51, 0x57, 0x42, 0x42, 0x52, 0x67, 0x65, 0x32, 0x59, 0x61, 0x52,
0x51, 0x32, 0x58, 0x79, 0x6F, 0x6C, 0x51, 0x4C, 0x33, 0x30, 0x45, 0x7A, 0x54, 0x53, 0x6F, 0x2F, 0x2F, 0x7A, 0x39, 0x53,
0x7A, 0x41, 0x4E, 0x42, 0x67, 0x6B, 0x71, 0x68, 0x6B, 0x69, 0x47, 0x39, 0x77, 0x30, 0x42, 0x0A, 0x41, 0x51, 0x55, 0x46,
0x41, 0x41, 0x4F, 0x43, 0x41, 0x51, 0x45, 0x41, 0x31, 0x6E, 0x50, 0x6E, 0x66, 0x45, 0x39, 0x32, 0x30, 0x49, 0x32, 0x2F,
0x37, 0x4C, 0x71, 0x69, 0x76, 0x6A, 0x54, 0x46, 0x4B, 0x44, 0x4B, 0x31, 0x66, 0x50, 0x78, 0x73, 0x6E, 0x43, 0x77, 0x72,
0x76, 0x51, 0x6D, 0x65, 0x55, 0x37, 0x39, 0x72, 0x58, 0x71, 0x6F, 0x52, 0x53, 0x4C, 0x62, 0x6C, 0x43, 0x4B, 0x4F, 0x7A,
0x0A, 0x79, 0x6A, 0x31, 0x68, 0x54, 0x64, 0x4E, 0x47, 0x43, 0x62, 0x4D, 0x2B, 0x77, 0x36, 0x44, 0x6A, 0x59, 0x31, 0x55,
0x62, 0x38, 0x72, 0x72, 0x76, 0x72, 0x54, 0x6E, 0x68, 0x51, 0x37, 0x6B, 0x34, 0x6F, 0x2B, 0x59, 0x76, 0x69, 0x69, 0x59,
0x37, 0x37, 0x36, 0x42, 0x51, 0x56, 0x76, 0x6E, 0x47, 0x43, 0x76, 0x30, 0x34, 0x7A, 0x63, 0x51, 0x4C, 0x63, 0x46, 0x47,
0x55, 0x6C, 0x35, 0x67, 0x45, 0x0A, 0x33, 0x38, 0x4E, 0x66, 0x6C, 0x4E, 0x55, 0x56, 0x79, 0x52, 0x52, 0x42, 0x6E, 0x4D,
0x52, 0x64, 0x64, 0x57, 0x51, 0x56, 0x44, 0x66, 0x39, 0x56, 0x4D, 0x4F, 0x79, 0x47, 0x6A, 0x2F, 0x38, 0x4E, 0x37, 0x79,
0x79, 0x35, 0x59, 0x30, 0x62, 0x32, 0x71, 0x76, 0x7A, 0x66, 0x76, 0x47, 0x6E, 0x39, 0x4C, 0x68, 0x4A, 0x49, 0x5A, 0x4A,
0x72, 0x67, 0x6C, 0x66, 0x43, 0x6D, 0x37, 0x79, 0x6D, 0x50, 0x0A, 0x41, 0x62, 0x45, 0x56, 0x74, 0x51, 0x77, 0x64, 0x70,
0x66, 0x35, 0x70, 0x4C, 0x47, 0x6B, 0x6B, 0x65, 0x42, 0x36, 0x7A, 0x70, 0x78, 0x78, 0x78, 0x59, 0x75, 0x37, 0x4B, 0x79,
0x4A, 0x65, 0x73, 0x46, 0x31, 0x32, 0x4B, 0x77, 0x76, 0x68, 0x48, 0x68, 0x6D, 0x34, 0x71, 0x78, 0x46, 0x59, 0x78, 0x6C,
0x64, 0x42, 0x6E, 0x69, 0x59, 0x55, 0x72, 0x2B, 0x57, 0x79, 0x6D, 0x58, 0x55, 0x61, 0x64, 0x0A, 0x44, 0x4B, 0x71, 0x43,
0x35, 0x4A, 0x6C, 0x52, 0x33, 0x58, 0x43, 0x33, 0x32, 0x31, 0x59, 0x39, 0x59, 0x65, 0x52, 0x71, 0x34, 0x56, 0x7A, 0x57,
0x39, 0x76, 0x34, 0x39, 0x33, 0x6B, 0x48, 0x4D, 0x42, 0x36, 0x35, 0x6A, 0x55, 0x72, 0x39, 0x54, 0x55, 0x2F, 0x51, 0x72,
0x36, 0x63, 0x66, 0x39, 0x74, 0x76, 0x65, 0x43, 0x58, 0x34, 0x58, 0x53, 0x51, 0x52, 0x6A, 0x62, 0x67, 0x62, 0x4D, 0x45,
0x0A, 0x48, 0x4D, 0x55, 0x66, 0x70, 0x49, 0x42, 0x76, 0x46, 0x53, 0x44, 0x4A, 0x33, 0x67, 0x79, 0x49, 0x43, 0x68, 0x33,
0x57, 0x5A, 0x6C, 0x58, 0x69, 0x2F, 0x45, 0x6A, 0x4A, 0x4B, 0x53, 0x5A, 0x70, 0x34, 0x41, 0x3D, 0x3D, 0x20, 0x2D, 0x2D,
0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D,
0x2D, 0x2D, 0x2D, 0x0D, 0x0A};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

仰望space

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值