本文整理汇总了Java中org.bouncycastle.crypto.util.PublicKeyFactory类的典型用法代码示例。如果您正苦于以下问题:Java PublicKeyFactory类的具体用法?Java PublicKeyFactory怎么用?Java PublicKeyFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PublicKeyFactory类属于org.bouncycastle.crypto.util包,在下文中一共展示了PublicKeyFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveCertificateVerifyMessage
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
protected void receiveCertificateVerifyMessage(ByteArrayInputStream buf)
throws IOException
{
byte[] clientCertificateSignature = TlsUtils.readOpaque16(buf);
assertEmpty(buf);
// Verify the CertificateVerify message contains a correct signature.
try
{
TlsSigner tlsSigner = TlsUtils.createTlsSigner(this.clientCertificateType);
tlsSigner.init(getContext());
org.bouncycastle.asn1.x509.Certificate x509Cert = this.clientCertificate.getCertificateAt(0);
SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(keyInfo);
tlsSigner.verifyRawSignature(clientCertificateSignature, publicKey, this.certificateVerifyHash);
}
catch (Exception e)
{
throw new TlsFatalAlert(AlertDescription.decrypt_error);
}
}
示例2: getPublicKey
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
public PublicKey getPublicKey() {
try {
SubjectPublicKeyInfo subjectPublicKeyInfo = getCertificate().getSubjectPublicKeyInfo();
RSAKeyParameters rsa = (RSAKeyParameters) PublicKeyFactory.createKey(subjectPublicKeyInfo);
RSAPublicKeySpec rsaSpec = new RSAPublicKeySpec(rsa.getModulus(), rsa.getExponent());
KeyFactory kf = KeyFactory.getInstance(DEFAULT_KEY_ALG);
PublicKey rsaPub = kf.generatePublic(rsaSpec);
return rsaPub;
} catch (Exception e) {
throw new RuntimeException("Error while getting Public Key: " + e.getMessage(), e);
}
}
示例3: testSampleWitnesses
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
@Test
public void testSampleWitnesses()
throws Exception
{
ECPublicKeyParameters pubKey = (ECPublicKeyParameters)PublicKeyFactory.createKey(encKey);
ECShuffledTranscriptVerifier verifier = new ECShuffledTranscriptVerifier(pubKey, new ByteArrayInputStream(getSequence(witnessTranscript, new MessageChooser()
{
@Override
public boolean chooseMessage(int index)
{
if (index % 2 == 0)
{
return false;
}
return true;
}
})), new ByteArrayInputStream(initialTranscript), new ByteArrayInputStream(finalTranscript));
verifier.verify();
}
示例4: testCorruptWitnesses
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
@Test
public void testCorruptWitnesses()
throws Exception
{
ECPublicKeyParameters pubKey = (ECPublicKeyParameters)PublicKeyFactory.createKey(encKey);
try
{
ECShuffledTranscriptVerifier verifier = new ECShuffledTranscriptVerifier(pubKey, new ByteArrayInputStream(initialTranscript), new ByteArrayInputStream(initialTranscript), new ByteArrayInputStream(finalTranscript));
verifier.verify();
TestCase.fail("corrupt messages not noticed");
}
catch (TranscriptVerificationException e)
{
TestCase.assertEquals("illegal object in getInstance: org.bouncycastle.asn1.DLSequence", e.getCause().getMessage());
}
}
示例5: processCertificateVerify
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
protected void processCertificateVerify(ServerHandshakeState state, byte[] body, byte[] certificateVerifyHash)
throws IOException
{
ByteArrayInputStream buf = new ByteArrayInputStream(body);
DigitallySigned clientCertificateVerify = DigitallySigned.parse(state.serverContext, buf);
TlsProtocol.assertEmpty(buf);
// Verify the CertificateVerify message contains a correct signature.
try
{
org.bouncycastle.asn1.x509.Certificate x509Cert = state.clientCertificate.getCertificateAt(0);
SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(keyInfo);
TlsSigner tlsSigner = TlsUtils.createTlsSigner(state.clientCertificateType);
tlsSigner.init(state.serverContext);
tlsSigner.verifyRawSignature(clientCertificateVerify.getAlgorithm(),
clientCertificateVerify.getSignature(), publicKey, certificateVerifyHash);
}
catch (Exception e)
{
throw new TlsFatalAlert(AlertDescription.decrypt_error);
}
}
示例6: receiveCertificateVerifyMessage
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
protected void receiveCertificateVerifyMessage(ByteArrayInputStream buf)
throws IOException
{
DigitallySigned clientCertificateVerify = DigitallySigned.parse(getContext(), buf);
assertEmpty(buf);
// Verify the CertificateVerify message contains a correct signature.
try
{
org.bouncycastle.asn1.x509.Certificate x509Cert = this.peerCertificate.getCertificateAt(0);
SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(keyInfo);
TlsSigner tlsSigner = TlsUtils.createTlsSigner(this.clientCertificateType);
tlsSigner.init(getContext());
tlsSigner.verifyRawSignature(clientCertificateVerify.getAlgorithm(),
clientCertificateVerify.getSignature(), publicKey, this.certificateVerifyHash);
}
catch (Exception e)
{
throw new TlsFatalAlert(AlertDescription.decrypt_error);
}
}
示例7: getPublicKey
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
public AsymmetricKeyParameter getPublicKey()
throws PKCSException
{
try
{
return PublicKeyFactory.createKey(this.getSubjectPublicKeyInfo());
}
catch (IOException e)
{
throw new PKCSException("error extracting key encoding: " + e.getMessage(), e);
}
}
示例8: processServerCertificate
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
public void processServerCertificate(Certificate serverCertificate)
throws IOException
{
if (serverCertificate.isEmpty())
{
throw new TlsFatalAlert(AlertDescription.bad_certificate);
}
org.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0);
SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
try
{
this.serverPublicKey = PublicKeyFactory.createKey(keyInfo);
}
catch (RuntimeException e)
{
throw new TlsFatalAlert(AlertDescription.unsupported_certificate);
}
// Sanity check the PublicKeyFactory
if (this.serverPublicKey.isPrivate())
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
this.rsaServerPublicKey = validateRSAPublicKey((RSAKeyParameters)this.serverPublicKey);
TlsUtils.validateKeyUsage(x509Cert, KeyUsage.keyEncipherment);
super.processServerCertificate(serverCertificate);
}
示例9: processServerCertificate
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
public void processServerCertificate(Certificate serverCertificate)
throws IOException
{
if (keyExchange != KeyExchangeAlgorithm.RSA_PSK)
{
throw new TlsFatalAlert(AlertDescription.unexpected_message);
}
if (serverCertificate.isEmpty())
{
throw new TlsFatalAlert(AlertDescription.bad_certificate);
}
org.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0);
SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
try
{
this.serverPublicKey = PublicKeyFactory.createKey(keyInfo);
}
catch (RuntimeException e)
{
throw new TlsFatalAlert(AlertDescription.unsupported_certificate);
}
// Sanity check the PublicKeyFactory
if (this.serverPublicKey.isPrivate())
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
this.rsaServerPublicKey = validateRSAPublicKey((RSAKeyParameters)this.serverPublicKey);
TlsUtils.validateKeyUsage(x509Cert, KeyUsage.keyEncipherment);
super.processServerCertificate(serverCertificate);
}
示例10: processCertificateVerify
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
protected void processCertificateVerify(ServerHandshakeState state, byte[] body, byte[] certificateVerifyHash)
throws IOException
{
ByteArrayInputStream buf = new ByteArrayInputStream(body);
byte[] clientCertificateSignature = TlsUtils.readOpaque16(buf);
TlsProtocol.assertEmpty(buf);
// Verify the CertificateVerify message contains a correct signature.
try
{
TlsSigner tlsSigner = TlsUtils.createTlsSigner(state.clientCertificateType);
tlsSigner.init(state.serverContext);
org.bouncycastle.asn1.x509.Certificate x509Cert = state.clientCertificate.getCertificateAt(0);
SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(keyInfo);
tlsSigner.verifyRawSignature(clientCertificateSignature, publicKey, certificateVerifyHash);
}
catch (Exception e)
{
throw new TlsFatalAlert(AlertDescription.decrypt_error);
}
}
示例11: processServerCertificate
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
public void processServerCertificate(Certificate serverCertificate)
throws IOException
{
if (tlsSigner == null)
{
throw new TlsFatalAlert(AlertDescription.unexpected_message);
}
if (serverCertificate.isEmpty())
{
throw new TlsFatalAlert(AlertDescription.bad_certificate);
}
org.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0);
SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
try
{
this.serverPublicKey = PublicKeyFactory.createKey(keyInfo);
}
catch (RuntimeException e)
{
throw new TlsFatalAlert(AlertDescription.unsupported_certificate);
}
if (!tlsSigner.isValidPublicKey(this.serverPublicKey))
{
throw new TlsFatalAlert(AlertDescription.certificate_unknown);
}
TlsUtils.validateKeyUsage(x509Cert, KeyUsage.digitalSignature);
super.processServerCertificate(serverCertificate);
}
示例12: extractDHPublicKeyParameters
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
public static DHPublicKeyParameters extractDHPublicKeyParameters(Certificate cert) throws IOException {
if (hasDHParameters(cert)) {
SubjectPublicKeyInfo keyInfo = cert.getCertificateAt(0).getSubjectPublicKeyInfo();
return (DHPublicKeyParameters) PublicKeyFactory.createKey(keyInfo);
} else {
throw new IOException();
}
}
示例13: extractECPublicKeyParameters
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
public static ECPublicKeyParameters extractECPublicKeyParameters(Certificate cert) throws IOException {
if (hasECParameters(cert)) {
SubjectPublicKeyInfo keyInfo = cert.getCertificateAt(0).getSubjectPublicKeyInfo();
return (ECPublicKeyParameters) PublicKeyFactory.createKey(keyInfo);
} else {
throw new IOException();
}
}
示例14: processServerCertificate
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
public void processServerCertificate(Certificate serverCertificate)
throws IOException
{
if (serverCertificate.isEmpty())
{
throw new TlsFatalAlert(AlertDescription.bad_certificate);
}
org.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0);
SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
try
{
this.serverPublicKey = PublicKeyFactory.createKey(keyInfo);
}
catch (RuntimeException e)
{
throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e);
}
// Sanity check the PublicKeyFactory
if (this.serverPublicKey.isPrivate())
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
this.rsaServerPublicKey = validateRSAPublicKey((RSAKeyParameters)this.serverPublicKey);
TlsUtils.validateKeyUsage(x509Cert, KeyUsage.keyEncipherment);
super.processServerCertificate(serverCertificate);
}
示例15: processServerCertificate
import org.bouncycastle.crypto.util.PublicKeyFactory; //导入依赖的package包/类
public void processServerCertificate(Certificate serverCertificate) throws IOException
{
if (keyExchange != KeyExchangeAlgorithm.RSA_PSK)
{
throw new TlsFatalAlert(AlertDescription.unexpected_message);
}
if (serverCertificate.isEmpty())
{
throw new TlsFatalAlert(AlertDescription.bad_certificate);
}
org.bouncycastle.asn1.x509.Certificate x509Cert = serverCertificate.getCertificateAt(0);
SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
try
{
this.serverPublicKey = PublicKeyFactory.createKey(keyInfo);
}
catch (RuntimeException e)
{
throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e);
}
// Sanity check the PublicKeyFactory
if (this.serverPublicKey.isPrivate())
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
this.rsaServerPublicKey = validateRSAPublicKey((RSAKeyParameters)this.serverPublicKey);
TlsUtils.validateKeyUsage(x509Cert, KeyUsage.keyEncipherment);
super.processServerCertificate(serverCertificate);
}