类 UPPayRSAUtil


  • public class UPPayRSAUtil
    extends java.lang.Object
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static java.lang.String bytesToHex​(byte[] bytes)
      将byte数组转换成16进制字符串
      static byte[] decrypt​(byte[] data)
      RSA解密运算。
      static byte[] decrypt​(java.security.PrivateKey priKey, byte[] data, java.lang.String padding, java.lang.String provider)
      RSA解密运算
      static byte[] encrypt​(byte[] data, java.security.PublicKey publicKey)
      RSA加密运算。
      static byte[] encryptDataBytes​(java.security.PublicKey publicKey, byte[] data)
      使用公钥对数据进行加密,并返回byte[]类型
      static java.security.PrivateKey generateRSAPrivateKey​(byte[] key)
      根据字节流产生私钥
      static java.security.PrivateKey generateRSAPrivateKey​(java.lang.String modulus, java.lang.String privateExponent)
      根据模和指数生成私钥
      static java.security.PublicKey generateRSAPublicKey​(byte[] key)
      根据字节流产生公钥
      static java.security.PublicKey generateRSAPublicKey​(java.lang.String modulus, java.lang.String publicExponent)
      根据模数和公钥指数生成公钥
      static java.security.PrivateKey getPrivateKey()  
      static java.security.PrivateKey getPrivateKey​(java.lang.String priKeyData)  
      static java.security.PublicKey getPublicKey()  
      static java.security.PublicKey getPublicKey​(java.lang.String modulus, java.lang.String publicExponent)  
      static java.security.PublicKey getPublicKeyPM()  
      static java.security.PublicKey getPublicKeyProduct()  
      static byte[] hexToBytes​(char[] hex)
      将16进制的字符数组转换成byte数组
      static byte[] hexToBytes​(java.lang.String hex)
      将16进制的字符串转换成bytes
      static java.lang.String publicDecrypt​(java.security.PublicKey key, byte[] enc)  
      static java.lang.String sha1​(byte[] raw)  
      static boolean verify​(java.lang.String msg, java.lang.String sign64, java.lang.String mode)  
      static boolean verifyPM​(byte[] message, byte[] signature)  
      static boolean verifyProduct​(byte[] message, byte[] signature)  
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 字段详细资料

      • RSA

        public static final java.lang.String RSA
        另请参阅:
        常量字段值
      • RSA_PADDING_MODE

        public static final java.lang.String RSA_PADDING_MODE
        另请参阅:
        常量字段值
      • ALGORITHM_RSA_SIGN

        public static final java.lang.String ALGORITHM_RSA_SIGN
        另请参阅:
        常量字段值
      • RSAKEYLEN

        public static final int RSAKEYLEN
        另请参阅:
        常量字段值
      • KEY_LABEL

        public static final java.lang.String KEY_LABEL
        key_lable:key_lable
        另请参阅:
        常量字段值
      • DATA

        public static final java.lang.String DATA
        data:data
        另请参阅:
        常量字段值
      • TEXT

        public static final java.lang.String TEXT
        text:text
        另请参阅:
        常量字段值
      • clientPublicKey

        public static java.security.PublicKey clientPublicKey
    • 构造器详细资料

      • UPPayRSAUtil

        public UPPayRSAUtil()
    • 方法详细资料

      • getPublicKey

        public static java.security.PublicKey getPublicKey()
      • getPrivateKey

        public static java.security.PrivateKey getPrivateKey()
      • encrypt

        public static byte[] encrypt​(byte[] data,
                                     java.security.PublicKey publicKey)
        RSA加密运算。
        参数:
        data -
        publicKey -
        返回:
        加密结果
      • decrypt

        public static byte[] decrypt​(byte[] data)
        RSA解密运算。
        参数:
        data -
        返回:
        解密成功则返回解密结果, 否则返回null.
      • decrypt

        public static byte[] decrypt​(java.security.PrivateKey priKey,
                                     byte[] data,
                                     java.lang.String padding,
                                     java.lang.String provider)
        RSA解密运算
        参数:
        priKey -
        data -
        padding -
        返回:
      • generateRSAPublicKey

        public static java.security.PublicKey generateRSAPublicKey​(byte[] key)
        根据字节流产生公钥
        参数:
        key -
        返回:
        公钥
      • generateRSAPrivateKey

        public static java.security.PrivateKey generateRSAPrivateKey​(byte[] key)
        根据字节流产生私钥
        参数:
        key -
        返回:
        私钥
      • generateRSAPrivateKey

        public static java.security.PrivateKey generateRSAPrivateKey​(java.lang.String modulus,
                                                                     java.lang.String privateExponent)
        根据模和指数生成私钥
        参数:
        modulus -
        privateExponent -
        返回:
        私钥
      • encryptDataBytes

        public static byte[] encryptDataBytes​(java.security.PublicKey publicKey,
                                              byte[] data)
                                       throws java.lang.Exception
        使用公钥对数据进行加密,并返回byte[]类型
        参数:
        publicKey -
        data -
        返回:
        抛出:
        java.lang.Exception
      • getPrivateKey

        public static java.security.PrivateKey getPrivateKey​(java.lang.String priKeyData)
                                                      throws java.lang.Exception
        抛出:
        java.lang.Exception
      • getPublicKey

        public static java.security.PublicKey getPublicKey​(java.lang.String modulus,
                                                           java.lang.String publicExponent)
                                                    throws java.security.NoSuchAlgorithmException,
                                                           java.security.spec.InvalidKeySpecException
        抛出:
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • generateRSAPublicKey

        public static java.security.PublicKey generateRSAPublicKey​(java.lang.String modulus,
                                                                   java.lang.String publicExponent)
        根据模数和公钥指数生成公钥
        参数:
        modulus -
        publicExponent -
        返回:
        公钥
      • getPublicKeyPM

        public static java.security.PublicKey getPublicKeyPM()
      • getPublicKeyProduct

        public static java.security.PublicKey getPublicKeyProduct()
      • verifyPM

        public static boolean verifyPM​(byte[] message,
                                       byte[] signature)
                                throws java.lang.Exception
        抛出:
        java.lang.Exception
      • verifyProduct

        public static boolean verifyProduct​(byte[] message,
                                            byte[] signature)
                                     throws java.lang.Exception
        抛出:
        java.lang.Exception
      • sha1

        public static java.lang.String sha1​(byte[] raw)
      • verify

        public static boolean verify​(java.lang.String msg,
                                     java.lang.String sign64,
                                     java.lang.String mode)
      • hexToBytes

        public static byte[] hexToBytes​(java.lang.String hex)
        将16进制的字符串转换成bytes
        参数:
        hex -
        返回:
        转化后的byte数组
      • hexToBytes

        public static byte[] hexToBytes​(char[] hex)
        将16进制的字符数组转换成byte数组
        参数:
        hex -
        返回:
        转换后的byte数组
      • bytesToHex

        public static java.lang.String bytesToHex​(byte[] bytes)
        将byte数组转换成16进制字符串
        参数:
        bytes -
        返回:
        16进制字符串
      • publicDecrypt

        public static java.lang.String publicDecrypt​(java.security.PublicKey key,
                                                     byte[] enc)