@Test public void testb() { int b = curve.getField().getb(); assertThat(b, is(greaterThanOrEqualTo(10))); try { MessageDigest h = MessageDigest.getInstance(ed25519.getHashAlgorithm()); assertThat(8 * h.getDigestLength(), is(equalTo(2 * b))); } catch (NoSuchAlgorithmException e) { fail(e.getMessage()); } }
/** * Sign aribitrary binary input. * * @param input the bytes to sign * @return the signature for the input from the NKey * * @throws GeneralSecurityException if there is an encryption problem * @throws IOException if there is a problem reading the data */ public byte[] sign(byte[] input) throws GeneralSecurityException, IOException { Signature sgr = new EdDSAEngine(MessageDigest.getInstance(NKey.ed25519.getHashAlgorithm())); PrivateKey sKey = getKeyPair().getPrivate(); sgr.initSign(sKey); sgr.update(input); return sgr.sign(); }
/** * Sign aribitrary binary input. * * @param input the bytes to sign * @return the signature for the input from the NKey * * @throws GeneralSecurityException if there is an encryption problem * @throws IOException if there is a problem reading the data */ public byte[] sign(byte[] input) throws GeneralSecurityException, IOException { Signature sgr = new EdDSAEngine(MessageDigest.getInstance(NKey.ed25519.getHashAlgorithm())); PrivateKey sKey = getKeyPair().getPrivate(); sgr.initSign(sKey); sgr.update(input); return sgr.sign(); }
/** * Verify a signature. * * @param input the bytes that were signed * @param signature the bytes for the signature * @return true if the signature matches this keys signature for the input. * * @throws GeneralSecurityException if there is an encryption problem * @throws IOException if there is a problem reading the data */ public boolean verify(byte[] input, byte[] signature) throws GeneralSecurityException, IOException { Signature sgr = new EdDSAEngine(MessageDigest.getInstance(NKey.ed25519.getHashAlgorithm())); PublicKey sKey = null; if (privateKeyAsSeed != null) { sKey = getKeyPair().getPublic(); } else { char[] encodedPublicKey = getPublicKey(); byte[] decodedPublicKey = decode(this.type, encodedPublicKey, false); EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(decodedPublicKey, NKey.ed25519); sKey = new EdDSAPublicKey(pubKeySpec); } sgr.initVerify(sKey); sgr.update(input); return sgr.verify(signature); }
/** * Verify a signature. * * @param input the bytes that were signed * @param signature the bytes for the signature * @return true if the signature matches this keys signature for the input. * * @throws GeneralSecurityException if there is an encryption problem * @throws IOException if there is a problem reading the data */ public boolean verify(byte[] input, byte[] signature) throws GeneralSecurityException, IOException { Signature sgr = new EdDSAEngine(MessageDigest.getInstance(NKey.ed25519.getHashAlgorithm())); PublicKey sKey = null; if (privateKeyAsSeed != null) { sKey = getKeyPair().getPublic(); } else { char[] encodedPublicKey = getPublicKey(); byte[] decodedPublicKey = decode(this.type, encodedPublicKey, false); EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(decodedPublicKey, NKey.ed25519); sKey = new EdDSAPublicKey(pubKeySpec); } sgr.initVerify(sKey); sgr.update(input); return sgr.verify(signature); }