项目:openjdk-jdk10
文件:ApiTest.java
/**
* Verify the exception type either it is expected to occur or not.
* @param alg Algorithm name
* @param param DRBG parameter
* @param e Exception to verify
* @throws NoSuchAlgorithmException
*/
private static void checkException(String alg,SecureRandomParameters param,NoSuchAlgorithmException e) throws NoSuchAlgorithmException {
int strength = ((Instantiation) param).getStrength();
boolean error = true;
switch (alg) {
case INVALID_ALGO:
error = false;
break;
case "SHA-224":
case "SHA-512/224":
if (strength > 192) {
error = false;
}
break;
case "SHA-256":
case "SHA-512/256":
case "SHA-384":
case "SHA-512":
if (strength > 256) {
error = false;
}
break;
case "AES-128":
case "AES-192":
case "AES-256":
int algoStrength = Integer.parseInt(alg.substring("AES-".length()));
int maxAEsstrength = Cipher.getMaxAllowedKeyLength("AES");
if (strength > algoStrength
|| algoStrength > maxAEsstrength) {
error = false;
}
break;
}
if (error) {
throw new RuntimeException("UnkNown :",e);
}
}
项目:openjdk9
文件:ApiTest.java
/**
* Verify the exception type either it is expected to occur or not.
* @param alg Algorithm name
* @param param DRBG parameter
* @param e Exception to verify
* @throws NoSuchAlgorithmException
*/
private static void checkException(String alg,NoSuchAlgorithmException e) throws NoSuchAlgorithmException {
int strength = ((Instantiation) param).getStrength();
boolean error = true;
switch (alg) {
case INVALID_ALGO:
error = false;
break;
case "SHA-224":
case "SHA-512/224":
if (strength > 192) {
error = false;
}
break;
case "SHA-256":
case "SHA-512/256":
case "SHA-384":
case "SHA-512":
if (strength > 256) {
error = false;
}
break;
case "AES-128":
case "AES-192":
case "AES-256":
int algoStrength = Integer.parseInt(alg.replaceAll("AES-",""));
int maxStrengthSupported = Cipher.getMaxAllowedKeyLength("AES");
if (strength > maxStrengthSupported
|| algoStrength > maxStrengthSupported) {
error = false;
}
break;
}
if (error) {
throw new RuntimeException("UnkNown :",e);
}
}
项目:demo-java-9
文件:Drbg.java
public static void main(String[] args) throws NoSuchAlgorithmException {
Instantiation instantiation = DrbgParameters.instantiation(128,RESEED_ONLY,null);
SecureRandom random = SecureRandom.getInstance("DRBG",instantiation);
byte[] bytes = new byte[20];
random.nextBytes(bytes);
for (byte b : bytes) {
System.out.print(b + " ");
}
System.out.println();
}
项目:openjdk-jdk10
文件:ApiTest.java
private static boolean isSupportPR(String mech,SecureRandom random) {
return (isDRBG(mech) && ((Instantiation) random.getParameters())
.getCapability()
.supportsPredictionResistance());
}
项目:openjdk9
文件:ApiTest.java
private static boolean isSupportPR(String mech,SecureRandom random) {
return (isDRBG(mech) && ((Instantiation) random.getParameters())
.getCapability()
.supportsPredictionResistance());
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。