當前位置: 首頁>>代碼示例>>Java>>正文


Java TrustManager.getTrustManager方法代碼示例

本文整理匯總了Java中com.sun.spot.peripheral.TrustManager.getTrustManager方法的典型用法代碼示例。如果您正苦於以下問題:Java TrustManager.getTrustManager方法的具體用法?Java TrustManager.getTrustManager怎麽用?Java TrustManager.getTrustManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.spot.peripheral.TrustManager的用法示例。


在下文中一共展示了TrustManager.getTrustManager方法的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();
			}
		}
	}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:22,代碼來源:StartApplication.java

示例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());
    }
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:34,代碼來源:Handshake.java


注:本文中的com.sun.spot.peripheral.TrustManager.getTrustManager方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。