use of won.cryptography.exception.KeyNotSupportedException in project webofneeds by researchstudio-sat.
the class CryptographyServiceTest method testInfoExractorOfKeyPairBrainpoolp384r1.
@Test
public void testInfoExractorOfKeyPairBrainpoolp384r1() {
KeyPairService keyPairService = context.getBean("keyPairService", KeyPairService.class);
KeyPair keypair = keyPairService.generateNewKeyPairInBrainpoolp384r1();
KeyInformationExtractorBouncyCastle extractor = new KeyInformationExtractorBouncyCastle();
try {
Assert.assertEquals("ECDSA", extractor.getAlgorithm(keypair.getPublic()));
logger.debug("algorithm: " + extractor.getAlgorithm(keypair.getPublic()));
Assert.assertEquals("brainpoolp384r1", extractor.getCurveID(keypair.getPublic()));
logger.debug("curveID: " + extractor.getCurveID(keypair.getPublic()));
Assert.assertNotNull(extractor.getQX(keypair.getPublic()));
logger.debug("qx: " + extractor.getQX(keypair.getPublic()));
Assert.assertNotNull(extractor.getQY(keypair.getPublic()));
logger.debug("qy: " + extractor.getQY(keypair.getPublic()));
} catch (KeyNotSupportedException ex) {
Assert.fail(ex.getMessage());
}
}
use of won.cryptography.exception.KeyNotSupportedException in project webofneeds by researchstudio-sat.
the class CryptographyServiceTest method testInfoExtractorOfKeyPairSecp384r1.
@Test
public void testInfoExtractorOfKeyPairSecp384r1() {
KeyPairService keyPairService = context.getBean("keyPairService", KeyPairService.class);
KeyPair keypair = keyPairService.generateNewKeyPairInSecp384r1();
KeyInformationExtractorBouncyCastle extractor = new KeyInformationExtractorBouncyCastle();
try {
Assert.assertEquals("ECDSA", extractor.getAlgorithm(keypair.getPublic()));
logger.debug("algorithm: " + extractor.getAlgorithm(keypair.getPublic()));
Assert.assertEquals("secp384r1", extractor.getCurveID(keypair.getPublic()));
logger.debug("curveID: " + extractor.getCurveID(keypair.getPublic()));
Assert.assertNotNull(extractor.getQX(keypair.getPublic()));
logger.debug("qx: " + extractor.getQX(keypair.getPublic()));
Assert.assertNotNull(extractor.getQY(keypair.getPublic()));
logger.debug("qy: " + extractor.getQY(keypair.getPublic()));
} catch (KeyNotSupportedException ex) {
Assert.fail(ex.getMessage());
}
}
use of won.cryptography.exception.KeyNotSupportedException in project webofneeds by researchstudio-sat.
the class KeyInformationExtractorBouncyCastle method getCurveID.
public String getCurveID(Key key) throws KeyNotSupportedException {
if (key instanceof ECKey) {
// doing this in a weird way. We changed this from an instanceof check for the
// ECParameterSpec class, which, due to some classloader magic gone wrong failed
// for the object which actually is of that class. I guess that the class is in
// multiple jars loaded from different classloaders... hard to know.
// This works.
ECParameterSpec spec = ((ECKey) key).getParams();
Class<?> clazz = spec.getClass();
try {
return (String) clazz.getDeclaredMethod("getName").invoke(spec);
} catch (Exception e) {
throw new KeyNotSupportedException("Cannot get curve name from ECParameterSpec " + spec, e);
}
} else {
throw new KeyNotSupportedException("Key is not an elliptic curve key!");
}
}
Aggregations