DSSPKUtils { public static String getPublicKeySize(Token token) { String keyLength = "?"; PublicKey issuerPublicKey = null; if (token.getPublicKeyOfTheSigner() != null) { issuerPublicKey = token.getPublicKeyOfTheSigner(); } else if (token.isSelfSigned()) { issuerPublicKey = ((CertificateToken) token).getPublicKey(); } if (issuerPublicKey != null) { keyLength = String.valueOf(getPublicKeySize(issuerPublicKey)); } return keyLength; } private  DSSPKUtils(); static String getPublicKeySize(Token token); static int getPublicKeySize(final PublicKey publicKey);  }
@Test public void getPublicKeySize() { CertificateToken certificate = DSSUtils.loadCertificate(new File("src/test/resources/BA-QC-Wurzel-CA-2_PN.txt")); assertEquals(2048, DSSPKUtils.getPublicKeySize(certificate.getPublicKey())); assertEquals("2048", DSSPKUtils.getPublicKeySize(certificate)); }
@Test public void getPublicKeySizeECDSA() { CertificateToken certificate = DSSUtils.loadCertificate(new File("src/test/resources/certificates/ecdsa.cer")); assertEquals(256, DSSPKUtils.getPublicKeySize(certificate.getPublicKey())); }
@Test public void getPublicKeySizeSelfSign() { CertificateToken certificate = DSSUtils.loadCertificate(new File("src/test/resources/certificates/belgiumrca2-self-sign.crt")); assertEquals(2048, DSSPKUtils.getPublicKeySize(certificate.getPublicKey())); assertEquals("2048", DSSPKUtils.getPublicKeySize(certificate)); }
@Test public void x25519() { CertificateToken token = DSSUtils.loadCertificateFromBase64EncodedString( "MIIBLDCB36ADAgECAghWAUdKKo3DMDAFBgMrZXAwGTEXMBUGA1UEAwwOSUVURiBUZXN0IERlbW8wHhcNMTYwODAxMTIxOTI0WhcNNDAxMjMxMjM1OTU5WjAZMRcwFQYDVQQDDA5JRVRGIFRlc3QgRGVtbzAqMAUGAytlbgMhAIUg8AmJMKdUdIt93LQ+91oNvzoNJjga9OukqY6qm05qo0UwQzAPBgNVHRMBAf8EBTADAQEAMA4GA1UdDwEBAAQEAwIDCDAgBgNVHQ4BAQAEFgQUmx9e7e0EM4Xk97xiPFl1uQvIuzswBQYDK2VwA0EAryMB/t3J5v/BzKc9dNZIpDmAgs3babFOTQbs+BolzlDUwsPrdGxO3YNGhW7Ibz3OGhhlxXrCe1Cgw1AH9efZBw=="); assertEquals(EncryptionAlgorithm.X25519, EncryptionAlgorithm.forKey(token.getPublicKey())); assertEquals(32, DSSPKUtils.getPublicKeySize(token.getPublicKey())); assertTrue(token.checkKeyUsage(KeyUsageBit.KEY_AGREEMENT)); }
@Test public void Ed25519() { CertificateToken token = DSSUtils.loadCertificateFromBase64EncodedString( "MIIBCDCBuwIUGW78zw0OL0GptJi++a91dBa7DsQwBQYDK2VwMCcxCzAJBgNVBAYTAkRFMRgwFgYDVQQDDA93d3cuZXhhbXBsZS5jb20wHhcNMTkwMzMxMTc1MTIyWhcNMjEwMjI4MTc1MTIyWjAnMQswCQYDVQQGEwJERTEYMBYGA1UEAwwPd3d3LmV4YW1wbGUuY29tMCowBQYDK2VwAyEAK87g0b8CC1eA5mvKXt9uezZwJYWEyg74Y0xTZEkqCcwwBQYDK2VwA0EAIIu/aa3Qtr3IE5to/nvWVY9y3ciwG5DnA70X3ALUhFs+U5aLtfY8sNT1Ng72ht+UBwByuze20UsL9qMsmknQCA=="); assertNotNull(token); assertEquals(EncryptionAlgorithm.ED25519, EncryptionAlgorithm.forKey(token.getPublicKey())); assertEquals(32, DSSPKUtils.getPublicKeySize(token.getPublicKey())); assertFalse(token.checkKeyUsage(KeyUsageBit.KEY_AGREEMENT)); }