AlgorithmParameterGenerator getAlgorithm() 方法在 Java 中
可以使用 類 java.security.AlgorithmParameterGenerator 中的方法 getAlgorithm() 獲取引數生成器的演算法名稱。此方法不需要任何引數,它以字串形式返回演算法名稱。
演示此方法的程式如下所示 −
示例
import java.security.*;
import java.util.*;
public class Demo {
public static void main(String[] argv) {
try {
AlgorithmParameterGenerator apGenerator = AlgorithmParameterGenerator.getInstance("DiffieHellman");
apGenerator.init(1024);
String algorithm = apGenerator.getAlgorithm();
System.out.println("The Algorithm is: " + algorithm);
} catch (NoSuchAlgorithmException e) {
System.out.println("Error!!! NoSuchAlgorithmException");
} catch (ProviderException e) {
System.out.println("Error!!! ProviderException");
}
}
}輸出
The Algorithm is: DiffieHellman
現在讓我們理解上述程式。
使用 getAlgorithm() 方法獲取引數生成器的演算法名稱。然後顯示此演算法名稱。如果演算法名稱錯誤,則會丟擲異常 NoSuchAlgorithmException。演示的程式碼片段如下所示 −
try {
AlgorithmParameterGenerator apGenerator = AlgorithmParameterGenerator.getInstance("DiffieHellman");
apGenerator.init(1024);
String algorithm = apGenerator.getAlgorithm();
System.out.println("The Algorithm is: " + algorithm);
} catch (NoSuchAlgorithmException e) {
System.out.println("Error!!! NoSuchAlgorithmException");
} catch (ProviderException e) {
System.out.println("Error!!! ProviderException");
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP