@Test public void loadKeyFromProperties() { String privateKey = App.getProperty("500006.channel.lenovo.appsecret", ""); logger.debug("loadKeyFromProperties() privateKey = " + privateKey); PrivateKey priKey = null; try { priKey = RSAUtil.parsePrivateKey(privateKey); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { e.printStackTrace(); } Assert.assertNotNull(priKey); }
public static RSAPrivateKey parsePrivateKey(String keyStr) throws NoSuchAlgorithmException, InvalidKeySpecException { logger.debug("parsePrivateKey() key:\n" + keyStr); KeyFactory kf = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(keyStr)); RSAPrivateKey key = (RSAPrivateKey) kf.generatePrivate(keySpec); return key; }
RSAUtil { public static RSAPrivateKey parsePrivateKey(String keyStr) throws NoSuchAlgorithmException, InvalidKeySpecException { logger.debug("parsePrivateKey() key:\n" + keyStr); KeyFactory kf = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(keyStr)); RSAPrivateKey key = (RSAPrivateKey) kf.generatePrivate(keySpec); return key; } }
RSAUtil { public static RSAPrivateKey parsePrivateKey(String keyStr) throws NoSuchAlgorithmException, InvalidKeySpecException { logger.debug("parsePrivateKey() key:\n" + keyStr); KeyFactory kf = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(keyStr)); RSAPrivateKey key = (RSAPrivateKey) kf.generatePrivate(keySpec); return key; }  }
RSAUtil { public static RSAPrivateKey parsePrivateKey(String keyStr) throws NoSuchAlgorithmException, InvalidKeySpecException { logger.debug("parsePrivateKey() key:\n" + keyStr); KeyFactory kf = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(keyStr)); RSAPrivateKey key = (RSAPrivateKey) kf.generatePrivate(keySpec); return key; }  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 RSAPrivateKey parsePrivateKey(String keyStr) throws NoSuchAlgorithmException, InvalidKeySpecException { logger.debug("parsePrivateKey() key:\n" + keyStr); KeyFactory kf = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(keyStr)); RSAPrivateKey key = (RSAPrivateKey) kf.generatePrivate(keySpec); return key; }  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);  }