com.yunzhanghu.example.utils.RSAUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk Show documentation
Show all versions of sdk Show documentation
云账户综合服务平台官方 SDK for Java,支持 Java JDK 1.8 及以上版本
Copyright © 2013 - 2024 云账户技术(天津)有限公司
云账户开放平台:https://open.yunzhanghu.com
package com.yunzhanghu.example.utils;
public class RSAUtil {
/**
* 将 RSA 密钥从 PEM 转 String 格式
*
* @param rsaKey PEM 格式的 RSA 密钥
* @return String 格式的 RSA 密钥
*/
public static String pem2String(String rsaKey) {
if (rsaKey.isEmpty()) {
throw new NullPointerException();
}
if (!rsaKey.startsWith("-")) {
return rsaKey;
}
String[] rsaKeyArr = null;
if (rsaKey.contains("\r")) {
rsaKeyArr = rsaKey.split("\r\n");
} else {
rsaKeyArr = rsaKey.split("\n");
}
StringBuffer sbf = new StringBuffer();
for (int i = 1; i < rsaKeyArr.length - 1; i++) {
sbf.append(rsaKeyArr[i]);
}
return sbf.toString().replace("\r\n", "").replace("\r", "").replace("\n", "");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy