gpt4 book ai didi

使用 WifiEnterpriseConfig setClientKeyEntry 的 Android Wifi EAP TLS

转载 作者:行者123 更新时间:2023-11-30 03:05:39 36 4
gpt4 key购买 nike

WifiEnterpriseConfig setClientKeyEntry 方法采用私钥和证书引用。我在 Android 证书库中存储了一个 .p12 证书。我可以使用 KeyChain API(getCertificateChain、getPrivateKey)获取私钥和​​证书引用并将其传递给 setClientKeyEntry 吗?或者,如果我有一个字符串或字节数组格式的 .p12 证书,那么我是否需要将它存储在证书存储中以便能够将它用于 Wifi EAP-TLS?

假设:在 Android 4.3+ 客户端上以编程方式设置 EAP-TLS 需要 setClientKeyEntry 方法。

最佳答案

试试这个:

WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"your_ssid\"";
wc.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
wc.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
wc.enterpriseConfig.setEapMethod(Eap.TLS);
wc.status = WifiConfiguration.Status.ENABLED;

...

KeyStore pkcs12ks = KeyStore.getInstance("pkcs12");

in = new BufferedInputStream(new FileInputStream(new File("/path/to/your.p12")));
// alternatively you can read from any input stream, e.g. ByteArrayInputStream to read from String

pkcs12ks.load(in, "pasword".toCharArray());

Enumeration<String> aliases = pkcs12ks.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
Log.d(TAG, "Processing alias " + alias);

X509Certificate cert = (X509Certificate) pkcs12ks.getCertificate(alias);
Log.d(TAG, cert.toString());

PrivateKey key = (PrivateKey) pkcs12ks.getKey(alias, "password".toCharArray());
Log.d(TAG, key.toString());

wc.enterpriseConfig.setClientKeyEntry(key, cert);
wc.enterpriseConfig.setIdentity("WiFi-1");
}

...

int netID = wifiManager.addNetwork(wc);
wifiManager.saveConfiguration();
wifiManager.enableNetwork(netID, true);

未显示正确的异常处理。

关于使用 WifiEnterpriseConfig setClientKeyEntry 的 Android Wifi EAP TLS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21861001/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com