KeyPair { public byte[] sign(byte[] data) { if (mPrivateKey == null) { throw new RuntimeException("KeyPair does not contain secret key. Use KeyPair.fromSecretSeed method to create a new KeyPair with a secret key."); } try { Signature sgr = new EdDSAEngine(MessageDigest.getInstance("SHA-512")); sgr.initSign(mPrivateKey); sgr.update(data); return sgr.sign(); } catch (GeneralSecurityException e) { throw new RuntimeException(e); } } KeyPair(EdDSAPublicKey publicKey);  KeyPair(EdDSAPublicKey publicKey, EdDSAPrivateKey privateKey); boolean canSign(); static KeyPair fromSecretSeed(char[] seed); static KeyPair fromSecretSeed(String seed); static KeyPair fromSecretSeed(byte[] seed); static KeyPair fromAccountId(String accountId); static KeyPair fromPublicKey(byte[] publicKey); static KeyPair random(); String getAccountId(); char[] getSecretSeed(); byte[] getRawSecretSeed(); byte[] getPublicKey(); SignatureHint getSignatureHint(); PublicKey getXdrPublicKey(); SignerKey getXdrSignerKey(); static KeyPair fromXdrPublicKey(PublicKey key); static KeyPair fromXdrSignerKey(SignerKey key); byte[] sign(byte[] data); DecoratedSignature signDecorated(byte[] data); boolean verify(byte[] data, byte[] signature); @Override boolean equals(Object obj);  }
@Test public void testSign() { String expectedSig = "587d4b472eeef7d07aafcd0b049640b0bb3f39784118c2e2b73a04fa2f64c9c538b4b2d0f5335e968a480021fdc23e98c0ddf424cb15d8131df8cb6c4bb58309"; KeyPair keypair = KeyPair.fromSecretSeed(Util.hexToBytes(SEED)); String data = "hello world"; byte[] sig = keypair.sign(data.getBytes()); Assert.assertArrayEquals(Util.hexToBytes(expectedSig), sig); }