本文整理匯總了Java中com.sun.spot.peripheral.TrustManager類的典型用法代碼示例。如果您正苦於以下問題:Java TrustManager類的具體用法?Java TrustManager怎麽用?Java TrustManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TrustManager類屬於com.sun.spot.peripheral包,在下文中一共展示了TrustManager類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: installCertificate
import com.sun.spot.peripheral.TrustManager; //導入依賴的package包/類
private void installCertificate(String certificateName) {
TrustManager trustManager = TrustManager.getTrustManager();
if(trustManager.getCertStore().getCertByNickname(certificateName) == null) {
// try {
// trustManager.getCertStore().addCert(certificateName, "", null);
// } catch (Exception e) {
// e.printStackTrace();
// }
try {
InputStream is = StartApplication.class.getResourceAsStream("/" + certificateName + ".cer");
byte[] buffer = new byte[4096];
int byteCount = is.read(buffer);
X509Certificate certificate = X509Certificate.generateCertificate(buffer, 0, byteCount);
trustManager.getCertStore().addCert(certificateName, "", certificate);
System.out.println("Installed certificate " + certificateName + " with fingerprint " + Utils.hexEncode(certificate.getFingerprint()));
trustManager.flashTrustManager();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例2: Handshake
import com.sun.spot.peripheral.TrustManager; //導入依賴的package包/類
/**
* Creates an Handshake object that is used to negotiate a
* version 3 handshake with an SSL peer.
*
* @param host hostname of the peer
* @param port port number of the peer
* @param r Record instance through which handshake
* will occur
* @param tcs trusted certificate store containing certificates
*
* @exception RuntimeException if SHA-1 or MD5 is not available
*/
Handshake(String host, int port, Record r, CertStore tcs) {
trustManager = TrustManager.getTrustManager(); // SPOT specific
peerHost = new String(host);
peerPort = port;
rec = r;
certStore = tcs;
sPrivKey = null;
gotCertReq = 0;
start = 0;
cnt = 0;
try {
ourMD5 = MessageDigest.getInstance("MD5");
ourSHA = MessageDigest.getInstance("SHA-1");
rnd = SecureRandom.getInstance(SecureRandom.ALG_SECURE_RANDOM);
} catch (NoSuchAlgorithmException e) {
// should only happen, if digests are not included in the build
throw new RuntimeException(e.getMessage());
}
}