1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public byte[] encrypt(byte[] data) throws Exception { if(publicKey == null || "".equals(publicKey)) { throw new Exception("publicKey is need exists"); } PublicKey rsaPublicKey = getRSAPublicKey(publicKey); Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.ENCRYPT_MODE, rsaPublicKey); return cipher.doFinal(data); }
public byte[] decrypt(byte[] data) throws Exception { if(publicKey == null || "".equals(publicKey)) { throw new Exception("publicKey is need exists"); } PublicKey rsaPublicKey = getRSAPublicKey(publicKey); Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, rsaPublicKey); return cipher.doFinal(data); }
public boolean verifySign(byte[] data, String sign) throws Exception { if(publicKey == null || "".equals(publicKey)) { throw new Exception("publicKey is need exists"); } PublicKey rsaPublicKey = getRSAPublicKey(publicKey); Signature signature = Signature.getInstance(SIGN_ALGORITHM); signature.initVerify(rsaPublicKey); signature.update(data); return signature.verify(decoder(sign)); }
|