Exemplo n.º 1
0
  public String generateSigature(String src) {
    try {
      Security.addProvider(new ABAProvider());
      Signature sigEng = Signature.getInstance("MD5withRSA", "ABA");

      byte[] pribyte = hexStrToBytes(priKey.trim());
      sigEng.initSign(new RSAPrivKeyCrt(pribyte));
      sigEng.update(src.getBytes());

      byte[] signature = sigEng.sign();
      return bytesToHexStr(signature);
    } catch (Exception e) {
      return null;
    }
  }
Exemplo n.º 2
0
  public boolean verifySigature(String sign, String src) {
    try {
      Security.addProvider(new ABAProvider());
      Signature sigEng = Signature.getInstance("MD5withRSA", "ABA");

      byte[] pubbyte = hexStrToBytes(pubKey.trim());
      sigEng.initVerify(new RSAPubKey(pubbyte));
      sigEng.update(src.getBytes());

      byte[] sign1 = hexStrToBytes(sign);
      if (sigEng.verify(sign1)) {
        return true;
      } else {
        return false;
      }

    } catch (Exception e) {
      return false;
    }
  }