Java 中的 Provider get() 方法


可使用 java.security.Provider 類中的 get() 方法獲取已對映到金鑰的值。此方法需要一個引數,即需要其值對應的金鑰。它將返回已對映到該金鑰的值,或者如果沒有任何值對映到該金鑰,則返回 null。

以下是演示此方法的程式 −

示例

 實際演示

import java.security.*;
import java.util.*;
public class Demo {
   public static void main(String[] argv) {
      try {
         SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");
         Provider p = sRandom.getProvider();
         Set<Object> set = p.keySet();
         Iterator i = set.iterator();
         int x = 30;
         while (x > 0) {
            Object val = p.get(i.next());
            System.out.println(val);
            x--;
         }
      } catch (NoSuchAlgorithmException e) {
         System.out.println("Error!!! NoSuchAlgorithmException");
      }
   }
}

以上程式的輸出如下 −

輸出

SHA1withDSA
SHA1withDSA
SHA1withDSA
Software
sun.security.provider.JavaKeyStore$DualFormatJKS
SHA
sun.security.provider.SHA
sun.security.provider.JavaKeyStore$CaseExactJKS
Software
sun.security.provider.DSA$SHA256withDSA
SHA
SHA1withDSA
Software
Software
Software
sun.security.provider.DSA$RawDSA
X.509
java.security.interfaces.DSAPublicKey|java.security.interfaces.DSAPrivateKey
sun.security.provider.certpath.IndexedCollectionCertStore
sun.security.provider.Sun
SHA
SHA1withDSA
sun.security.provider.DomainKeyStore$DKS
Software
SHA256withDSA
SHA224withDSA
1024
1024
Software
sun.security.provider.DSAKeyFactory

更新日期: 2019 年 7 月 30 日

322 次瀏覽

開啟您的 職業生涯

透過完成課程,獲得認證

開始
廣告
© . All rights reserved.