Search in sources :

Example 1 with KeyNotSupportedException

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());
    }
}
Also used : KeyPair(java.security.KeyPair) KeyNotSupportedException(won.cryptography.exception.KeyNotSupportedException) KeyInformationExtractorBouncyCastle(won.cryptography.key.KeyInformationExtractorBouncyCastle) KeyPairService(won.cryptography.service.KeyPairService) Test(org.junit.Test)

Example 2 with KeyNotSupportedException

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());
    }
}
Also used : KeyPair(java.security.KeyPair) KeyNotSupportedException(won.cryptography.exception.KeyNotSupportedException) KeyInformationExtractorBouncyCastle(won.cryptography.key.KeyInformationExtractorBouncyCastle) KeyPairService(won.cryptography.service.KeyPairService) Test(org.junit.Test)

Example 3 with KeyNotSupportedException

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!");
    }
}
Also used : ECParameterSpec(java.security.spec.ECParameterSpec) KeyNotSupportedException(won.cryptography.exception.KeyNotSupportedException) ECKey(java.security.interfaces.ECKey) KeyNotSupportedException(won.cryptography.exception.KeyNotSupportedException)

Aggregations

KeyNotSupportedException (won.cryptography.exception.KeyNotSupportedException)3 KeyPair (java.security.KeyPair)2 Test (org.junit.Test)2 KeyInformationExtractorBouncyCastle (won.cryptography.key.KeyInformationExtractorBouncyCastle)2 KeyPairService (won.cryptography.service.KeyPairService)2 ECKey (java.security.interfaces.ECKey)1 ECParameterSpec (java.security.spec.ECParameterSpec)1