public CryptoBox(Streamable data, byte[] encryptionKey) throws IOException { this(data, Security.keyToPoint(encryptionKey)); }
/** * @param data to check * @param signature the signature of the message * @param pubkey the sender's public key * @return true if the signature is valid, false otherwise */ public static boolean isSignatureValid(byte[] data, byte[] signature, Pubkey pubkey) { try { ECParameterSpec spec = new ECParameterSpec( EC_CURVE_PARAMETERS.getCurve(), EC_CURVE_PARAMETERS.getG(), EC_CURVE_PARAMETERS.getN(), EC_CURVE_PARAMETERS.getH(), EC_CURVE_PARAMETERS.getSeed() ); ECPoint Q = keyToPoint(pubkey.getSigningKey()); KeySpec keySpec = new ECPublicKeySpec(Q, spec); PublicKey publicKey = KeyFactory.getInstance("ECDSA", "BC").generatePublic(keySpec); Signature sig = Signature.getInstance("ECDSA", "BC"); sig.initVerify(publicKey); sig.update(data); return sig.verify(signature); } catch (Exception e) { throw new RuntimeException(e); } }