public class RSAUtils extends Object
限定符和类型 | 方法和说明 |
---|---|
protected static byte[] |
asciiToBcd(byte[] ascii,
int ascLen)
ASCII码转BCD码
|
protected static byte |
ascToBcd(byte asc) |
protected static String |
bcd2Str(byte[] bytes)
BCD转字符串
|
static String |
decryptByPrivateKey(String data,
RSAPrivateKey privateKey)
私钥解密
|
static String |
encryptByPublicKey(String data,
RSAPublicKey publicKey)
公钥加密
|
static Map<String,Object> |
getKeys()
生成公钥和私钥
|
static RSAPrivateKey |
getPrivateKey(String modulus,
String exponent)
使用模和指数生成RSA私钥
注意:【此代码用了默认补位方式,为RSA/None/PKCS1Padding,不同JDK默认的补位方式可能不同,如Android默认是RSA
/None/NoPadding】
|
static RSAPublicKey |
getPublicKey(String modulus,
String exponent)
使用模和指数生成RSA公钥
注意:【此代码用了默认补位方式,为RSA/None/PKCS1Padding,不同JDK默认的补位方式可能不同,如Android默认是RSA
/None/NoPadding】
|
protected static byte[][] |
splitArray(byte[] data,
int len)
拆分数组
|
protected static String[] |
splitString(String string,
int len)
拆分字符串
|
public static Map<String,Object> getKeys() throws NoSuchAlgorithmException
public static RSAPublicKey getPublicKey(String modulus, String exponent)
modulus
- 模exponent
- 指数public static RSAPrivateKey getPrivateKey(String modulus, String exponent)
modulus
- 模exponent
- 指数public static String encryptByPublicKey(String data, RSAPublicKey publicKey) throws Exception
data
- publicKey
- Exception
public static String decryptByPrivateKey(String data, RSAPrivateKey privateKey) throws Exception
data
- privateKey
- Exception
protected static byte[] asciiToBcd(byte[] ascii, int ascLen)
protected static byte ascToBcd(byte asc)
protected static String bcd2Str(byte[] bytes)
protected static byte[][] splitArray(byte[] data, int len)