# Encryption **Repository Path**: royedvamp/encryption ## Basic Information - **Project Name**: Encryption - **Description**: RSA加解密算法 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-06-19 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Encryption #### 项目介绍 RSA加解密算法 #### 使用说明 1. 生成公钥和私钥 RSAEncrypt.genKeyPair(filepath); 2. 公钥加密私钥解密 //公钥加密过程 byte[] cipherData = RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile(filepath)), plainText.getBytes()); String cipher = Base64.encode(cipherData); //私钥解密过程 byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile(filepath)), Base64.decode(cipher)); String restr = new String(res); 3. 私钥加密公钥解密过程 //私钥加密过程 byte[] cipherData = RSAEncrypt.encrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile(filepath)),plainText.getBytes()); String cipher = Base64.encode(cipherData); //公钥解密过程 byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile(filepath)), Base64.decode(cipher)); String restr = new String(res); 4. 私钥签名过程 String signstr = RSASignature.sign(content,RSAEncrypt.loadPrivateKeyByFile(filepath)); 5. 公钥校验签名 RSASignature.doCheck(content, signstr, RSAEncrypt.loadPublicKeyByFile(filepath));