本文整理匯總了Java中org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter.getPublicKey方法的典型用法代碼示例。如果您正苦於以下問題:Java JcaPEMKeyConverter.getPublicKey方法的具體用法?Java JcaPEMKeyConverter.getPublicKey怎麽用?Java JcaPEMKeyConverter.getPublicKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter
的用法示例。
在下文中一共展示了JcaPEMKeyConverter.getPublicKey方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verifyUserSig
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; //導入方法依賴的package包/類
@Override
public boolean verifyUserSig(String identifier, String sig)throws QCloudException {
try {
Security.addProvider(new BouncyCastleProvider());
//DeBaseUrl64 urlSig to json
Base64 decoder = new Base64();
byte [] compressBytes = Base64Url.base64DecodeUrl(sig.getBytes(Charset.forName("UTF-8")));
//Decompression
Inflater decompression = new Inflater();
decompression.setInput(compressBytes, 0, compressBytes.length);
byte [] decompressBytes = new byte [1024];
int decompressLength = decompression.inflate(decompressBytes);
decompression.end();
String jsonString = new String(Arrays.copyOfRange(decompressBytes, 0, decompressLength));
//Get TLS.Sig from json
JSONObject jsonObject= JSON.parseObject(jsonString);
String sigTLS = jsonObject.getString("TLS.sig");
//debase64 TLS.Sig to get serailString
byte[] signatureBytes = decoder.decode(sigTLS.getBytes(Charset.forName("UTF-8")));
String strSdkAppid = jsonObject.getString("TLS.sdk_appid");
String sigTime = jsonObject.getString("TLS.time");
String sigExpire = jsonObject.getString("TLS.expire_after");
if (!imConfig.getSdkAppId().equals(strSdkAppid))
{
return false;
}
if ( System.currentTimeMillis()/1000 - Long.parseLong(sigTime) > Long.parseLong(sigExpire)) {
return false;
}
//Get Serial String from json
String SerialString =
"TLS.appid_at_3rd:" + 0 + "\n" +
"TLS.account_type:" + 0 + "\n" +
"TLS.identifier:" + identifier + "\n" +
"TLS.sdk_appid:" + imConfig.getSdkAppId() + "\n" +
"TLS.time:" + sigTime + "\n" +
"TLS.expire_after:" + sigExpire + "\n";
Reader reader = new CharArrayReader(imConfig.getPublicKey().toCharArray());
PEMParser parser = new PEMParser(reader);
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
Object obj = parser.readObject();
parser.close();
PublicKey pubKeyStruct = converter.getPublicKey((SubjectPublicKeyInfo) obj);
Signature signature = Signature.getInstance("SHA256withECDSA","BC");
signature.initVerify(pubKeyStruct);
signature.update(SerialString.getBytes(Charset.forName("UTF-8")));
return signature.verify(signatureBytes);
}catch (Exception e) {
throw new QCloudException(e);
}
}
示例2: buildCertificateRequest
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; //導入方法依賴的package包/類
@Override
public String buildCertificateRequest() {
try {
CompanyInfo companyInfo = wsaaDao.loadActiveCompanyInfo();
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
PEMKeyPair pemPrivateKey = fromPem(companyInfo.getPrivateKey());
PrivateKey privateKey = converter.getPrivateKey(pemPrivateKey
.getPrivateKeyInfo());
PEMKeyPair pemPublicKey = fromPem(companyInfo.getPrivateKey());
PublicKey publicKey = converter.getPublicKey(pemPublicKey
.getPublicKeyInfo());
X500Principal subject = new X500Principal(companyInfo.buildSource());
ContentSigner signGen = new JcaContentSignerBuilder(SIGNING_ALGORITHM)
.build(privateKey);
PKCS10CertificationRequest csr = new JcaPKCS10CertificationRequestBuilder(
subject, publicKey).build(signGen);
return toPem(csr);
} catch (IOException | OperatorCreationException e) {
throw Throwables.propagate(e);
}
}
示例3: extractX509CSRPublicKey
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; //導入方法依賴的package包/類
public static String extractX509CSRPublicKey(PKCS10CertificationRequest certReq) {
JcaPEMKeyConverter pemConverter = new JcaPEMKeyConverter();
PublicKey publicKey = null;
try {
publicKey = pemConverter.getPublicKey(certReq.getSubjectPublicKeyInfo());
} catch (PEMException ex) {
LOG.error("extractX509CSRPublicKey: unable to get public key: {}", ex.getMessage());
return null;
}
return convertToPEMFormat(publicKey);
}
示例4: getPublicKey
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; //導入方法依賴的package包/類
public static PublicKey getPublicKey(String keyString) {
PublicKey publicKey = null;
try {
BufferedReader br = new BufferedReader(new StringReader(keyString));
PEMParser pp = new PEMParser(br);
SubjectPublicKeyInfo publicKeyInfo = (SubjectPublicKeyInfo) pp.readObject();
pp.close();
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
publicKey = converter.getPublicKey(publicKeyInfo);
} catch (Exception e) {
ProtoLogger.error("!!! Error importing public key !!!");
}
return publicKey;
}
示例5: readPublicKey
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; //導入方法依賴的package包/類
private PublicKey readPublicKey(String publicKeyPath) throws IOException {
FileReader fileReader = new FileReader(publicKeyPath);
PEMParser keyReader = new PEMParser(fileReader);
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
Object keyPair = keyReader.readObject();
keyReader.close();
return converter.getPublicKey((SubjectPublicKeyInfo)keyPair);
}