use of sun.security.provider.DSAPrivateKey in project jdk8u_jdk by JetBrains.
the class PKCS8Test method main.
public static void main(String[] args) throws IOException, InvalidKeyException {
BigInteger x = BigInteger.valueOf(1);
BigInteger p = BigInteger.valueOf(2);
BigInteger q = BigInteger.valueOf(3);
BigInteger g = BigInteger.valueOf(4);
DSAPrivateKey priv = new DSAPrivateKey(x, p, q, g);
byte[] encodedKey = priv.getEncoded();
byte[] expectedBytes = new byte[EXPECTED.length];
for (int i = 0; i < EXPECTED.length; i++) {
expectedBytes[i] = (byte) EXPECTED[i];
}
dumpByteArray("encodedKey :", encodedKey);
if (!Arrays.equals(encodedKey, expectedBytes)) {
raiseException(new String(expectedBytes), new String(encodedKey));
}
PKCS8Key decodedKey = PKCS8Key.parse(new DerValue(encodedKey));
String alg = decodedKey.getAlgorithm();
AlgorithmId algId = decodedKey.getAlgorithmId();
out.println("Algorithm :" + alg);
out.println("AlgorithmId: " + algId);
if (!ALGORITHM.equals(alg)) {
raiseException(ALGORITHM, alg);
}
if (!EXPECTED_ALG_ID_CHRS.equalsIgnoreCase(algId.toString())) {
raiseException(EXPECTED_ALG_ID_CHRS, algId.toString());
}
decodedKey.encode(derOutput);
dumpByteArray("Stream encode: ", derOutput.toByteArray());
if (!Arrays.equals(derOutput.toByteArray(), expectedBytes)) {
raiseException(new String(expectedBytes), derOutput.toString());
}
dumpByteArray("byte[] encoding: ", decodedKey.getEncoded());
if (!Arrays.equals(decodedKey.getEncoded(), expectedBytes)) {
raiseException(new String(expectedBytes), new String(decodedKey.getEncoded()));
}
if (!FORMAT.equals(decodedKey.getFormat())) {
raiseException(FORMAT, decodedKey.getFormat());
}
try {
byte[] newEncodedKey = new byte[NEW_ENCODED_KEY_INTS.length];
for (int i = 0; i < newEncodedKey.length; i++) {
newEncodedKey[i] = (byte) NEW_ENCODED_KEY_INTS[i];
}
PKCS8Key newDecodedKey = PKCS8Key.parse(new DerValue(newEncodedKey));
throw new RuntimeException("key1: Expected an IOException during " + "parsing");
} catch (IOException e) {
System.out.println("newEncodedKey: should have excess data due to " + "attributes, which are not supported");
}
try {
byte[] newEncodedKey2 = new byte[NEW_ENCODED_KEY_INTS_2.length];
for (int i = 0; i < newEncodedKey2.length; i++) {
newEncodedKey2[i] = (byte) NEW_ENCODED_KEY_INTS_2[i];
}
PKCS8Key newDecodedKey2 = PKCS8Key.parse(new DerValue(newEncodedKey2));
throw new RuntimeException("key2: Expected an IOException during " + "parsing");
} catch (IOException e) {
out.println("Key 2: should be illegal version");
out.println(e.getMessage());
if (!EXCEPTION_MESSAGE.equals(e.getMessage())) {
throw new RuntimeException("Key2: expected: " + EXCEPTION_MESSAGE + " get: " + e.getMessage());
}
}
}
use of sun.security.provider.DSAPrivateKey in project jdk8u_jdk by JetBrains.
the class SolarisShortDSA method main.
public static void main(String[] args) throws Exception {
for (int i = 0; i < 10000; i++) {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA");
KeyPair kp = kpg.generateKeyPair();
DSAPrivateKey dpk = (DSAPrivateKey) kp.getPrivate();
int len = dpk.getX().bitLength();
if (len <= 152) {
if (!use(kp)) {
String os = System.getProperty("os.name");
// Solaris bug, update the following line once it's fixed
if (os.equals("SunOS")) {
throw new IllegalStateException("Don't panic. This is a Solaris bug");
} else {
throw new RuntimeException("Real test failure");
}
}
break;
}
}
}
Aggregations