예제 #1
0
  public boolean generateKeys() {

    PublicKey keyPub;
    PrivateKey keyPri;
    SecureRandom rand;

    Security.addProvider(new ABAProvider());

    rand = new SecureRandom();

    rand.setSeed(System.currentTimeMillis());

    try {
      KeyPairGenerator fact;
      KeyPair keyPair;

      fact = KeyPairGenerator.getInstance("RSA", "ABA");

      fact.initialize(1024, rand);

      keyPair = fact.generateKeyPair();

      keyPub = keyPair.getPublic();

      keyPri = keyPair.getPrivate();

      pubKey = bytesToHexStr(keyPub.getEncoded());

      priKey = bytesToHexStr(keyPri.getEncoded());
    } catch (Exception e) {
      return false;
    }
    return true;
  }
예제 #2
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;
    }
  }
예제 #3
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;
    }
  }