@Test public void testSignMessage() { Object[][] testcases = new Object[][]{ new Object[]{"Hello imToken".getBytes(), "648081bc111e6116769bdb4396eebe17f58d3eddc0aeb04a868990deac9dfa2f322514a380fa66e0e864faaac6ef936092cdc022f5fd7d61cb501193ede537b31b"}, new Object[]{"a".getBytes(), "5caec23c6aa80c772fef1a52655cbb46ed5e017573b054ba8d3fa61d9d26df9848a8a544478726b4b2140b444831c2f0bbd97c819e1344482190c2ad265865ca1c"}, new Object[]{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".getBytes(), "65e4952899a8dcadf3a65a11bdac0f0cfdf93e0bae5c67674c78a72631de524d3cafe27ea71c86aa3fd838c6a50a0b09d6ece85a6dcf3ce85c30fdc51380ebdf1b"}, new Object[]{ByteBuffer.allocate(4).putInt(1234567).array(), "2d4a505a90d3a27a71d987fbbd377414e79e69e889e1b3d3dda15f5c1aa2c0624a907df6c5e41eba108749d9220173df42c1dff153eb25cf3a9576a2b9fede511b"}, new Object[]{ByteBuffer.allocate(4).putInt(0).array(), "511cf92b0838ba64f844fd2fdf8c2806dfc3dcc0f6b4ec552c7a7c0171e9ada07dd5625a788d4f80c4906ec5dc9e783a4c764c1d1632ebf6b35f7015415396711c"}, new Object[]{NumericUtil.bigIntegerToBytesWithZeroPadded(new BigInteger("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"), 64), "d2dc01447baa8bc298d5e97fbeb4a126026b58f98f15427986c1c2bcede3da170531079ce0bd491e68e7a20a0b5758449596b123dfce196d89823c44ed6f47c61c"}, }; for (Object[] aCase : testcases) { Assert.assertEquals(aCase[1], EthereumSign.signMessage((byte[]) aCase[0], privateKey).toString()); } }
static SignatureData signMessage(byte[] message, byte[] prvKeyBytes) { ECKey ecKey = ECKey.fromPrivate(prvKeyBytes); byte[] messageHash = Hash.keccak256(message); return signAsRecoverable(messageHash, ecKey); }
EthereumSign { static SignatureData signMessage(byte[] message, byte[] prvKeyBytes) { ECKey ecKey = ECKey.fromPrivate(prvKeyBytes); byte[] messageHash = Hash.keccak256(message); return signAsRecoverable(messageHash, ecKey); } }
EthereumSign { static SignatureData signMessage(byte[] message, byte[] prvKeyBytes) { ECKey ecKey = ECKey.fromPrivate(prvKeyBytes); byte[] messageHash = Hash.keccak256(message); return signAsRecoverable(messageHash, ecKey); }  }
EthereumSign { static SignatureData signMessage(byte[] message, byte[] prvKeyBytes) { ECKey ecKey = ECKey.fromPrivate(prvKeyBytes); byte[] messageHash = Hash.keccak256(message); return signAsRecoverable(messageHash, ecKey); }  static String personalSign(String data, byte[] prvKeyBytes); static String sign(String data, byte[] prvKeyBytes); static BigInteger ecRecover(String data, String signature); static String recoverAddress(String data, String signature); static SignatureData signAsRecoverable(byte[] value, ECKey ecKey); }
EthereumSign { static SignatureData signMessage(byte[] message, byte[] prvKeyBytes) { ECKey ecKey = ECKey.fromPrivate(prvKeyBytes); byte[] messageHash = Hash.keccak256(message); return signAsRecoverable(messageHash, ecKey); }  static String personalSign(String data, byte[] prvKeyBytes); static String sign(String data, byte[] prvKeyBytes); static BigInteger ecRecover(String data, String signature); static String recoverAddress(String data, String signature); static SignatureData signAsRecoverable(byte[] value, ECKey ecKey);  }