Java Code Examples for java.security.SignatureException#printStackTrace()

The following examples show how to use java.security.SignatureException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignatureBench.java    From bumblebench with Apache License 2.0 6 votes vote down vote up
protected long doBatch(long numIterations) throws InterruptedException {
    try {
        for (long i = 0; i < numIterations; i++) {
            if (exeMode == 1) {
               sig.update(data);
               signatureBytes = sig.sign();
            } else if (exeMode == 2) {
               sig.update(data);
               sig.verify(signatureBytes, 0, signatureBytes.length);
            }
        }
    } catch (SignatureException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return numIterations;
}
 
Example 2
Source File: TransactionUtils.java    From gsc-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static boolean validTransaction(Transaction signedTransaction) {
  assert (signedTransaction.getSignatureCount()
      == signedTransaction.getRawData().getContractCount());
  List<Transaction.Contract> listContract = signedTransaction.getRawData().getContractList();
  byte[] hash = Sha256Hash.hash(signedTransaction.getRawData().toByteArray());
  int count = signedTransaction.getSignatureCount();
  if (count == 0) {
    return false;
  }
  for (int i = 0; i < count; ++i) {
    try {
      Transaction.Contract contract = listContract.get(i);
      byte[] owner = getOwner(contract);
      byte[] address = ECKey
          .signatureToAddress(hash, getBase64FromByteString(signedTransaction.getSignature(i)));
      if (!Arrays.equals(owner, address)) {
        return false;
      }
    } catch (SignatureException e) {
      e.printStackTrace();
      return false;
    }
  }
  return true;
}
 
Example 3
Source File: DappBrowserFragment.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
public void testRecoverAddressFromSignature(String message, String sig)
{
    String prefix = PERSONAL_MESSAGE_PREFIX + message.length();
    byte[] msgHash = (prefix + message).getBytes();

    byte[] signatureBytes = Numeric.hexStringToByteArray(sig);
    Sign.SignatureData sd = sigFromByteArray(signatureBytes);
    String addressRecovered;

    try
    {
        BigInteger recoveredKey = Sign.signedMessageToKey(msgHash, sd);
        addressRecovered = "0x" + Keys.getAddress(recoveredKey);
        System.out.println("Recovered: " + addressRecovered);
    }
    catch (SignatureException e)
    {
        e.printStackTrace();
    }
}
 
Example 4
Source File: TransactionUtils.java    From tron-wallet-android with Apache License 2.0 6 votes vote down vote up
public static boolean validTransaction(Transaction signedTransaction) {
  assert (signedTransaction.getSignatureCount() ==
      signedTransaction.getRawData().getContractCount());
  List<Transaction.Contract> listContract = signedTransaction.getRawData().getContractList();
  byte[] hash = sha256(signedTransaction.getRawData().toByteArray());
  int count = signedTransaction.getSignatureCount();
  if (count == 0) {
    return false;
  }
  for (int i = 0; i < count; ++i) {
    try {
      Transaction.Contract contract = listContract.get(i);
      byte[] owner = getOwner(contract);
      byte[] address = ECKey
          .signatureToAddress(hash, getBase64FromByteString(signedTransaction.getSignature(i)));
      if (!Arrays.equals(owner, address)) {
        return false;
      }
    } catch (SignatureException e) {
      e.printStackTrace();
      return false;
    }
  }
  return true;
}
 
Example 5
Source File: ZipSigner.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
@Override public void write(@NonNull byte[] buffer, int offset, int length) throws IOException {
  try {
    signature.update(buffer, offset, length);
  } catch (SignatureException e) {
    e.printStackTrace();
  }
  super.write(buffer, offset, length);
}
 
Example 6
Source File: ZipSigner.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
@Override public void write(int oneByte) throws IOException {
  try {
    signature.update((byte) oneByte);
  } catch (SignatureException e) {
    e.printStackTrace();
  }
  super.write(oneByte);
}
 
Example 7
Source File: PrivateKeyUtil.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public static boolean verifyMessage(String address, String messageText, String signatureText) {
    // Strip CRLF from signature text
    try {
        signatureText = signatureText.replaceAll("\n", "").replaceAll("\r", "");

        ECKey key = ECKey.signedMessageToKey(messageText, signatureText);
        String signAddress = key.toAddress();
        return Utils.compareString(address, signAddress);
    } catch (SignatureException e) {
        e.printStackTrace();
        return false;
    }

}