/** * Signs a text message using the standard Bitcoin messaging signing format and returns the signature as a base64 * encoded string. * * @throws IllegalStateException if this ECKey does not have the private part. * @throws KeyCrypterException if this ECKey is encrypted and no AESKey is provided or it does not decrypt the ECKey. */ public String signMessage(String message) throws KeyCrypterException { return signMessage(message, null); }
/** * Signs a text message using the standard Bitcoin messaging signing format and returns the signature as a base64 * encoded string. * * @throws IllegalStateException if this ECKey does not have the private part. * @throws KeyCrypterException if this ECKey is encrypted and no AESKey is provided or it does not decrypt the ECKey. */ public String signMessage(String message) throws KeyCrypterException { return signMessage(message, null); }
/** * Signs a text message using the standard Bitcoin messaging signing format and returns the signature as a base64 * encoded string. * * @throws IllegalStateException if this ECKey does not have the private part. * @throws KeyCrypterException if this ECKey is encrypted and no AESKey is provided or it does not decrypt the ECKey. */ public String signMessage(String message) throws KeyCrypterException { return signMessage(message, null); }
/** * Signs a text message using the standard Bitcoin messaging signing format and returns the signature as a base64 * encoded string. * * @throws IllegalStateException if this ECKey does not have the private part. * @throws KeyCrypterException if this ECKey is encrypted and no AESKey is provided or it does not decrypt the ECKey. */ public String signMessage(String message) throws KeyCrypterException { return signMessage(message, null); }
@Override public void signMessage(SignedMessage unsignedMessage, @Nullable KeyParameter aesKey) { String message = unsignedMessage.message; lock.lock(); try { ECKey key; try { BitAddress address = BitAddress.from(type, unsignedMessage.getAddress()); key = findKeyFromPubHash(address.getHash160()); } catch (AddressMalformedException e) { unsignedMessage.status = SignedMessage.Status.AddressMalformed; return; } if (key == null) { unsignedMessage.status = SignedMessage.Status.MissingPrivateKey; return; } try { unsignedMessage.signature = key.signMessage(type.getSignedMessageHeader(), message, aesKey); unsignedMessage.status = SignedMessage.Status.SignedOK; } catch (ECKey.KeyIsEncryptedException e) { unsignedMessage.status = SignedMessage.Status.KeyIsEncrypted; } catch (ECKey.MissingPrivateKeyException e) { unsignedMessage.status = SignedMessage.Status.MissingPrivateKey; } } finally { lock.unlock(); } }
@Override public void signMessage(SignedMessage unsignedMessage, @Nullable KeyParameter aesKey) { String message = unsignedMessage.message; lock.lock(); try { ECKey key; try { BitAddress address = BitAddress.from(type, unsignedMessage.getAddress()); key = findKeyFromPubHash(address.getHash160()); } catch (AddressMalformedException e) { unsignedMessage.status = SignedMessage.Status.AddressMalformed; return; } if (key == null) { unsignedMessage.status = SignedMessage.Status.MissingPrivateKey; return; } try { unsignedMessage.signature = key.signMessage(type.getSignedMessageHeader(), message, aesKey); unsignedMessage.status = SignedMessage.Status.SignedOK; } catch (ECKey.KeyIsEncryptedException e) { unsignedMessage.status = SignedMessage.Status.KeyIsEncrypted; } catch (ECKey.MissingPrivateKeyException e) { unsignedMessage.status = SignedMessage.Status.MissingPrivateKey; } } finally { lock.unlock(); } }
/** * This will deactivate push notifications. * @param node used to sign GUID. * @return * @throws Exception */ public Observable<ResponseBody> unregisterMdid(ECKey node) { log.info("Unregister mdid - deactivate push notifications"); String signedGuid = node.signMessage(walletBaseBody.getWalletBody().getGuid()); return walletApi.unregisterMdid(walletBaseBody.getWalletBody().getGuid(), walletBaseBody.getWalletBody().getSharedKey(), signedGuid); }
/** * This will activate push notifications. * @param node used to sign GUID. * @return * @throws Exception */ public Observable<ResponseBody> registerMdid(ECKey node) { log.info("Register mdid - activate push notifications"); String signedGuid = node.signMessage(walletBaseBody.getWalletBody().getGuid()); return walletApi.registerMdid(walletBaseBody.getWalletBody().getGuid(), walletBaseBody.getWalletBody().getSharedKey(), signedGuid); }
ECKey decryptedSigningKey = signingKey.decrypt(aesKey); String signatureBase64 = decryptedSigningKey.signMessage(messageText); return new SignMessageResult(Optional.of(signatureBase64), true, CoreMessageKey.SIGN_MESSAGE_SUCCESS, null); } else {
@Test public void signMessage() throws Exception { ECKey key = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); key.verifyMessage("test", key.signMessage("test")); }
/** * Delete metadata entry */ public void deleteMetadata(String payload) throws IOException, InvalidCipherTextException, MetadataException { byte[] encryptedPayloadBytes; if (isEncrypted) { //base64 to buffer encryptedPayloadBytes = Base64.decode(AESUtil.encryptWithKey(encryptionKey, payload)); } else { encryptedPayloadBytes = payload.getBytes("utf-8"); } byte[] message = MetadataUtil.message(encryptedPayloadBytes, magicHash); String signature = node.signMessage(new String(Base64.encode(message))); Call<Void> response = getApiInstance().deleteMetadata(address, signature); Response<Void> exe = response.execute(); if (!exe.isSuccessful()) { throw new MetadataException(exe.code() + " " + exe.message()); } else { magicHash = null; } }
@Test public void signTextMessage() throws Exception { ECKey key = new ECKey(); String message = "聡中本"; String signatureBase64 = key.signMessage(message); log.info("Message signed with " + key.toAddress(MainNetParams.get()) + ": " + signatureBase64); // Should verify correctly. key.verifyMessage(message, signatureBase64); try { key.verifyMessage("Evil attacker says hello!", signatureBase64); fail(); } catch (SignatureException e) { // OK. } }
String signature = node.signMessage(new String(Base64.encode(message)));