CryptoPrimitives implements CryptoSuite { @Override public byte[] sign(PrivateKey key, byte[] data) throws CryptoException { return ecdsaSignToBytes((ECPrivateKey) key, data); } CryptoPrimitives(); Certificate bytesToCertificate(byte[] certBytes); PrivateKey bytesToPrivateKey(byte[] pemKey); @Override boolean verify(byte[] pemCertificate, String signatureAlgorithm, byte[] signature, byte[] plainText); KeyStore getTrustStore(); void addCACertificateToTrustStore(File caCertPem, String alias); void addCACertificateToTrustStore(byte[] bytes, String alias); @Override void loadCACertificates(Collection<Certificate> certificates); @Override void loadCACertificatesAsBytes(Collection<byte[]> certificatesBytes); @Override KeyPair keyGen(); @Override byte[] sign(PrivateKey key, byte[] data); String generateCertificationRequest(String subject, KeyPair pair); @Override byte[] hash(byte[] input); @Override CryptoSuiteFactory getCryptoSuiteFactory(); void init(); @Override Properties getProperties(); byte[] certificateToDER(String certificatePEM);  }
@Test public void testSignNullKey() { try { crypto.sign(null, new byte[] {(byte) 0x00}); Assert.fail("sign() should have thrown an exception"); } catch (CryptoException e) { } }
@Test @Ignore public void testSign() { byte[] plainText = "123456".getBytes(UTF_8); byte[] signature; try { PrivateKey key = (PrivateKey) crypto.getTrustStore().getKey("key", "123456".toCharArray()); signature = crypto.sign(key, plainText); BufferedInputStream bis = new BufferedInputStream( this.getClass().getResourceAsStream("/keypair-signed.crt")); byte[] cert = IOUtils.toByteArray(bis); bis.close(); assertTrue(crypto.verify(cert, SIGNING_ALGORITHM, signature, plainText)); } catch (KeyStoreException | CryptoException | IOException | UnrecoverableKeyException | NoSuchAlgorithmException e) { fail("Could not verify signature. Error: " + e.getMessage()); } }