@Test public void loadKeyFromResource() { logger.debug("loadKeyFromResource() key.pub = " + getClass().getResource("/test/key.pub").getPath()); try { RSAPublicKey pubKey = RSAUtil.loadPublicKey(getClass().getResource("/test/key.pub").getPath()); Assert.assertNotNull("can load pub key", pubKey); } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException e) { logger.fatal("loadKeyFromResource() " + e.getMessage(), e); } }
public static RSAPublicKey loadPublicKey(String keyFilePath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { String s = FileUtils.readFileToString(new File(keyFilePath), "ISO-8859-1"); logger.debug("loadPublicKey() key:\n" + s); if (StringUtils.contains(s, "KEY-----\n")) { s = StringUtils.substringBetween(s, " KEY-----\n", "\n-----END "); } return parsePublicKey(s); }
RSAUtil { public static RSAPublicKey loadPublicKey(String keyFilePath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { String s = FileUtils.readFileToString(new File(keyFilePath), "ISO-8859-1"); logger.debug("loadPublicKey() key:\n" + s); if (StringUtils.contains(s, "KEY-----\n")) { s = StringUtils.substringBetween(s, " KEY-----\n", "\n-----END "); } return parsePublicKey(s); } }
RSAUtil { public static RSAPublicKey loadPublicKey(String keyFilePath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { String s = FileUtils.readFileToString(new File(keyFilePath), "ISO-8859-1"); logger.debug("loadPublicKey() key:\n" + s); if (StringUtils.contains(s, "KEY-----\n")) { s = StringUtils.substringBetween(s, " KEY-----\n", "\n-----END "); } return parsePublicKey(s); }  }
RSAUtil { public static RSAPublicKey loadPublicKey(String keyFilePath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { String s = FileUtils.readFileToString(new File(keyFilePath), "ISO-8859-1"); logger.debug("loadPublicKey() key:\n" + s); if (StringUtils.contains(s, "KEY-----\n")) { s = StringUtils.substringBetween(s, " KEY-----\n", "\n-----END "); } return parsePublicKey(s); }  static void generateKeyPair(String keyFilePath); static RSAPrivateKey loadPrivateKey(String keyFilePath); static RSAPrivateKey parsePrivateKey(String keyStr); static RSAPublicKey loadPublicKey(String keyFilePath); static RSAPublicKey parsePublicKey(String keyStr); static byte[] enc(String txt, Key key); static String enc2str(String txt, Key key); static byte[] dec(byte[] data, Key key); static StringBuilder bytesToHexString(byte[] bytesArray); static String HmacSHA1Encrypt(byte[] encryptData, String encryptKey); static String signWithSHA1WithRSA(String content, String privateKey, String input_charset); static String signWithHmacSHA1(String content, String privateKey); static String sign(byte[] content, PrivateKey priKey, String dsa); static boolean verify(byte[] data, String sign, PublicKey pubKey, String dsa); }
RSAUtil { public static RSAPublicKey loadPublicKey(String keyFilePath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { String s = FileUtils.readFileToString(new File(keyFilePath), "ISO-8859-1"); logger.debug("loadPublicKey() key:\n" + s); if (StringUtils.contains(s, "KEY-----\n")) { s = StringUtils.substringBetween(s, " KEY-----\n", "\n-----END "); } return parsePublicKey(s); }  static void generateKeyPair(String keyFilePath); static RSAPrivateKey loadPrivateKey(String keyFilePath); static RSAPrivateKey parsePrivateKey(String keyStr); static RSAPublicKey loadPublicKey(String keyFilePath); static RSAPublicKey parsePublicKey(String keyStr); static byte[] enc(String txt, Key key); static String enc2str(String txt, Key key); static byte[] dec(byte[] data, Key key); static StringBuilder bytesToHexString(byte[] bytesArray); static String HmacSHA1Encrypt(byte[] encryptData, String encryptKey); static String signWithSHA1WithRSA(String content, String privateKey, String input_charset); static String signWithHmacSHA1(String content, String privateKey); static String sign(byte[] content, PrivateKey priKey, String dsa); static boolean verify(byte[] data, String sign, PublicKey pubKey, String dsa);  }