test_class.declarator: publicKey
test_class.modifier: private
test_class.original_string: private String publicKey;
test_class.type: String
test_class.var_name: publicKey
test_class.declarator: privateKey
test_class.modifier: private
test_class.original_string: private String privateKey;
test_class.type: String
test_class.var_name: privateKey
test_class.file: buukle-main/buukle-util/src/main/java/top/buukle/util/RSA/RSACoderTest.java
test_class.identifier: RSACoderTest
test_case.body: @Test
      public void testSign() throws Exception {
          System.out.println("私钥加密——公钥解密");
          String inputStr = "sign";
          byte[] data = inputStr.getBytes();
  
          byte[] encodedData = RSACoder.encryptByPrivateKey(data, privateKey);
  
          byte[] decodedData = RSACoder.decryptByPublicKey(encodedData, publicKey);
  
          String outputStr = new String(decodedData);
          System.out.println("加密前: " + inputStr + "\n\r" + "解密后: " + outputStr);
          assertEquals(inputStr, outputStr);
  
          System.out.println("私钥签名——公钥验证签名");
          // 产生签名
          String sign = RSACoder.sign(encodedData, privateKey);
          System.out.println("签名:" + sign);
  
          // 验证签名
          boolean status = RSACoder.verify(encodedData, publicKey, sign);
          System.out.println("状态:" + status);
          assertTrue(status);
  
      }
test_case.class_method_signature: RSACoderTest.testSign()
test_case.full_signature: @Test public void testSign()
test_case.identifier: testSign
test_case.invocations: println getBytes encryptByPrivateKey decryptByPublicKey println assertEquals println sign println verify println assertTrue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testSign()
focal_class.declarator: KEY_ALGORITHM = "RSA"
focal_class.modifier: public static final
focal_class.original_string: public static final String KEY_ALGORITHM = "RSA";
focal_class.type: String
focal_class.var_name: KEY_ALGORITHM
focal_class.declarator: SIGNATURE_ALGORITHM = "MD5withRSA"
focal_class.modifier: public static final
focal_class.original_string: public static final String SIGNATURE_ALGORITHM = "MD5withRSA";
focal_class.type: String
focal_class.var_name: SIGNATURE_ALGORITHM
focal_class.declarator: PUBLIC_KEY = "RSAPublicKey"
focal_class.modifier: private static final
focal_class.original_string: private static final String PUBLIC_KEY = "RSAPublicKey";
focal_class.type: String
focal_class.var_name: PUBLIC_KEY
focal_class.declarator: PRIVATE_KEY = "RSAPrivateKey"
focal_class.modifier: private static final
focal_class.original_string: private static final String PRIVATE_KEY = "RSAPrivateKey";
focal_class.type: String
focal_class.var_name: PRIVATE_KEY
focal_class.file: buukle-main/buukle-util/src/main/java/top/buukle/util/RSA/RSACoder.java
focal_class.identifier: RSACoder
focal_class.class_method_signature: RSACoder.sign(byte[] data, String privateKey)
focal_class.full_signature: public static String sign(byte[] data, String privateKey)
focal_class.identifier: sign
focal_class.modifiers: public static
focal_class.parameters: (byte[] data, String privateKey)
focal_class.return: String
focal_class.signature: String sign(byte[] data, String privateKey)
focal_class.class_method_signature: RSACoder.verify(byte[] data, String publicKey, String sign)
focal_class.full_signature: public static boolean verify(byte[] data, String publicKey, String sign)
focal_class.identifier: verify
focal_class.modifiers: public static
focal_class.parameters: (byte[] data, String publicKey, String sign)
focal_class.return: boolean
focal_class.signature: boolean verify(byte[] data, String publicKey, String sign)
focal_class.class_method_signature: RSACoder.decryptByPrivateKey(byte[] data, String key)
focal_class.full_signature: public static byte[] decryptByPrivateKey(byte[] data, String key)
focal_class.identifier: decryptByPrivateKey
focal_class.modifiers: public static
focal_class.parameters: (byte[] data, String key)
focal_class.return: byte[]
focal_class.signature: byte[] decryptByPrivateKey(byte[] data, String key)
focal_class.class_method_signature: RSACoder.decryptByPublicKey(byte[] data, String key)
focal_class.full_signature: public static byte[] decryptByPublicKey(byte[] data, String key)
focal_class.identifier: decryptByPublicKey
focal_class.modifiers: public static
focal_class.parameters: (byte[] data, String key)
focal_class.return: byte[]
focal_class.signature: byte[] decryptByPublicKey(byte[] data, String key)
focal_class.class_method_signature: RSACoder.encryptByPublicKey(byte[] data, String key)
focal_class.full_signature: public static byte[] encryptByPublicKey(byte[] data, String key)
focal_class.identifier: encryptByPublicKey
focal_class.modifiers: public static
focal_class.parameters: (byte[] data, String key)
focal_class.return: byte[]
focal_class.signature: byte[] encryptByPublicKey(byte[] data, String key)
focal_class.class_method_signature: RSACoder.encryptByPrivateKey(byte[] data, String key)
focal_class.full_signature: public static byte[] encryptByPrivateKey(byte[] data, String key)
focal_class.identifier: encryptByPrivateKey
focal_class.modifiers: public static
focal_class.parameters: (byte[] data, String key)
focal_class.return: byte[]
focal_class.signature: byte[] encryptByPrivateKey(byte[] data, String key)
focal_class.class_method_signature: RSACoder.getPrivateKey(Map<String, Object> keyMap)
focal_class.full_signature: public static String getPrivateKey(Map<String, Object> keyMap)
focal_class.identifier: getPrivateKey
focal_class.modifiers: public static
focal_class.parameters: (Map<String, Object> keyMap)
focal_class.return: String
focal_class.signature: String getPrivateKey(Map<String, Object> keyMap)
focal_class.class_method_signature: RSACoder.getPublicKey(Map<String, Object> keyMap)
focal_class.full_signature: public static String getPublicKey(Map<String, Object> keyMap)
focal_class.identifier: getPublicKey
focal_class.modifiers: public static
focal_class.parameters: (Map<String, Object> keyMap)
focal_class.return: String
focal_class.signature: String getPublicKey(Map<String, Object> keyMap)
focal_class.class_method_signature: RSACoder.initKey()
focal_class.full_signature: public static Map<String, Object> initKey()
focal_class.identifier: initKey
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: Map<String, Object>
focal_class.signature: Map<String, Object> initKey()
focal_class.superclass: extends Coder
focal_method.body: public static String sign(byte[] data, String privateKey) throws Exception {
          // 解密由base64编码的私钥
          byte[] keyBytes = decryptBASE64(privateKey);
  
          // 构造PKCS8EncodedKeySpec对象
          PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
  
          // KEY_ALGORITHM 指定的加密算法
          KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
  
          // 取私钥匙对象
          PrivateKey priKey = keyFactory.generatePrivate(pkcs8KeySpec);
  
          // 用私钥对信息生成数字签名
          Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
          signature.initSign(priKey);
          signature.update(data);
  
          return encryptBASE64(signature.sign());
      }
focal_method.class_method_signature: RSACoder.sign(byte[] data, String privateKey)
focal_method.full_signature: public static String sign(byte[] data, String privateKey)
focal_method.identifier: sign
focal_method.invocations: decryptBASE64 getInstance generatePrivate getInstance initSign update encryptBASE64 sign
focal_method.modifiers: public static
focal_method.parameters: (byte[] data, String privateKey)
focal_method.return: String
focal_method.signature: String sign(byte[] data, String privateKey)