本文整理汇总了Java中org.bouncycastle.crypto.encodings.PKCS1Encoding类的典型用法代码示例。如果您正苦于以下问题:Java PKCS1Encoding类的具体用法?Java PKCS1Encoding怎么用?Java PKCS1Encoding使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PKCS1Encoding类属于org.bouncycastle.crypto.encodings包,在下文中一共展示了PKCS1Encoding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decryptPreMasterSecret
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public byte[] decryptPreMasterSecret(byte[] encryptedPreMasterSecret)
throws IOException
{
PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
encoding.init(false, new ParametersWithRandom(this.privateKey, context.getSecureRandom()));
try
{
return encoding.processBlock(encryptedPreMasterSecret, 0,
encryptedPreMasterSecret.length);
}
catch (InvalidCipherTextException e)
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
}
示例2: encryptKeyRSA
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public static byte[] encryptKeyRSA(AKey encryptionKey, ASecretKey toBeEncrypted) throws Exception
{
PKCS1Encoding rsa = new PKCS1Encoding(new RSAEngine());
rsa.init(true, getCipherParameters(encryptionKey));
byte[] k = toBeEncrypted.toByteArray();
try
{
byte[] encrypted = rsa.processBlock(k, 0, k.length);
return encrypted;
}
finally
{
Crypto.zero(k);
}
}
示例3: getRSADecryptCipher
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
/**
* @return an RSA decryption cipher
*/
protected synchronized AsymmetricBlockCipher getRSADecryptCipher()
{
if (decodeCipher == null)
{
try
{
byte[] bytes = getEncoder().decode(privateKey);
EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(bytes);
KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
PrivateKey key = keyFactory.generatePrivate(privateKeySpec);
this.decodeCipher = new PKCS1Encoding(new RSABlindedEngine());
decodeCipher.init(false, generatePrivateKeyParameter((RSAPrivateKey) key));
}
catch (Exception e)
{
throw new RuntimeException("Error constructing Cipher: ", e);
}
}
return decodeCipher;
}
示例4: getRSAEncryptCipher
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
/**
* @return
*/
protected synchronized AsymmetricBlockCipher getRSAEncryptCipher()
{
if (encodeCipher == null)
{
try
{
byte[] bytes = getEncoder().decode(publicKey);
EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(bytes);
KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
PublicKey key = keyFactory.generatePublic(publicKeySpec);
this.encodeCipher = new PKCS1Encoding(new RSABlindedEngine());
encodeCipher.init(true, generatePublicKeyParameter((RSAPublicKey) key));
}
catch (Exception e)
{
throw new RuntimeException("Error constructing Cipher: ", e);
}
}
return encodeCipher;
}
示例5: verifySignature
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
/**
* checks signature of PKCS1-padded SHA1 hash of the input
*
* Hint: A different implementation of this method can be found in the svn history revision<=229.
*
* @param signature
* signature to check
* @param signingKey
* public key from signing
* @param input
* byte array, signature is made over
*
* @return true, if the signature is correct
*
*/
public static boolean verifySignature(byte[] signature, RSAPublicKeyStructure signingKey, byte[] input) {
byte[] hash = getDigest(input);
try {
RSAKeyParameters myRSAKeyParameters = new RSAKeyParameters(false,
signingKey.getModulus(), signingKey.getPublicExponent());
PKCS1Encoding pkcsAlg = new PKCS1Encoding(new RSAEngine());
pkcsAlg.init(false, myRSAKeyParameters);
byte[] decryptedSignature = pkcsAlg.processBlock(signature, 0, signature.length);
return Encoding.arraysEqual(hash, decryptedSignature);
} catch (Exception e) {
log.log(Level.WARNING, "unexpected", e);
return false;
}
}
示例6: generateClientKeyExchange
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public byte[] generateClientKeyExchange() throws IOException
{
/*
* Choose a PremasterSecret and send it encrypted to the server
*/
premasterSecret = new byte[48];
handler.getRandom().nextBytes(premasterSecret);
TlsUtils.writeVersion(premasterSecret, 0);
PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
encoding.init(true, new ParametersWithRandom(this.rsaServerPublicKey, handler.getRandom()));
try
{
return encoding.processBlock(premasterSecret, 0, premasterSecret.length);
}
catch (InvalidCipherTextException e)
{
/*
* This should never happen, only during decryption.
*/
handler.failWithError(TlsProtocolHandler.AL_fatal, TlsProtocolHandler.AP_internal_error);
return null; // Unreachable!
}
}
示例7: createRSAImpl
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
protected AsymmetricBlockCipher createRSAImpl()
{
/*
* RFC 5264 7.4.7.1. Implementation note: It is now known that remote timing-based attacks
* on TLS are possible, at least when the client and server are on the same LAN.
* Accordingly, implementations that use static RSA keys MUST use RSA blinding or some other
* anti-timing technique, as described in [TIMING].
*/
return new PKCS1Encoding(new RSABlindedEngine());
}
示例8: generateEncryptedPreMasterSecret
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public static byte[] generateEncryptedPreMasterSecret(TlsContext context, RSAKeyParameters rsaServerPublicKey,
OutputStream output)
throws IOException
{
/*
* Choose a PremasterSecret and send it encrypted to the server
*/
byte[] premasterSecret = new byte[48];
context.getSecureRandom().nextBytes(premasterSecret);
TlsUtils.writeVersion(context.getClientVersion(), premasterSecret, 0);
PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
encoding.init(true, new ParametersWithRandom(rsaServerPublicKey, context.getSecureRandom()));
try
{
byte[] encryptedPreMasterSecret = encoding.processBlock(premasterSecret, 0, premasterSecret.length);
if (context.getServerVersion().isSSL())
{
// TODO Do any SSLv3 servers actually expect the length?
output.write(encryptedPreMasterSecret);
}
else
{
TlsUtils.writeOpaque16(encryptedPreMasterSecret, output);
}
}
catch (InvalidCipherTextException e)
{
/*
* This should never happen, only during decryption.
*/
throw new TlsFatalAlert(AlertDescription.internal_error);
}
return premasterSecret;
}
示例9: generateEncryptedPreMasterSecret
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public static byte[] generateEncryptedPreMasterSecret(TlsContext context, RSAKeyParameters rsaServerPublicKey,
OutputStream output) throws IOException
{
/*
* Choose a PremasterSecret and send it encrypted to the server
*/
byte[] premasterSecret = new byte[48];
context.getSecureRandom().nextBytes(premasterSecret);
TlsUtils.writeVersion(context.getClientVersion(), premasterSecret, 0);
PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
encoding.init(true, new ParametersWithRandom(rsaServerPublicKey, context.getSecureRandom()));
try
{
byte[] encryptedPreMasterSecret = encoding.processBlock(premasterSecret, 0, premasterSecret.length);
if (TlsUtils.isSSL(context))
{
// TODO Do any SSLv3 servers actually expect the length?
output.write(encryptedPreMasterSecret);
}
else
{
TlsUtils.writeOpaque16(encryptedPreMasterSecret, output);
}
}
catch (InvalidCipherTextException e)
{
/*
* This should never happen, only during decryption.
*/
throw new TlsFatalAlert(AlertDescription.internal_error, e);
}
return premasterSecret;
}
示例10: PKCS1v1_5Padding_PrivateOnly
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public PKCS1v1_5Padding_PrivateOnly()
{
super(new PKCS1Encoding(new NativeRSAEngine()));
try {
engineSetMode("1");// private key only
}
catch(Exception e) {
throw new RuntimeException( "bug", e );
}
}
示例11: PKCS1v1_5Padding_PublicOnly
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public PKCS1v1_5Padding_PublicOnly()
{
super(new PKCS1Encoding(new NativeRSAEngine()));
try {
engineSetMode("2");// public key only
}
catch(Exception e) {
throw new RuntimeException( "bug", e );
}
}
示例12: decryptKeyRSA
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public static ASecretKey decryptKeyRSA(AKey encryptionKey, byte[] b) throws Exception
{
PKCS1Encoding rsa = new PKCS1Encoding(new RSAEngine());
rsa.init(false, getCipherParameters(encryptionKey));
byte[] decrypted = rsa.processBlock(b, 0, b.length);
try
{
return new ASecretKey(decrypted);
}
finally
{
Crypto.zero(decrypted);
}
}
示例13: generateEncryptedPreMasterSecret
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public static byte[] generateEncryptedPreMasterSecret(TlsContext context, RSAKeyParameters rsaServerPublicKey,
OutputStream output) throws IOException
{
/*
* Choose a PremasterSecret and send it encrypted to the server
*/
byte[] premasterSecret = new byte[48];
context.getSecureRandom().nextBytes(premasterSecret);
TlsUtils.writeVersion(context.getClientVersion(), premasterSecret, 0);
PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
encoding.init(true, new ParametersWithRandom(rsaServerPublicKey, context.getSecureRandom()));
try
{
byte[] encryptedPreMasterSecret = encoding.processBlock(premasterSecret, 0, premasterSecret.length);
if (TlsUtils.isSSL(context))
{
// TODO Do any SSLv3 servers actually expect the length?
output.write(encryptedPreMasterSecret);
}
else
{
TlsUtils.writeOpaque16(encryptedPreMasterSecret, output);
}
}
catch (InvalidCipherTextException e)
{
/*
* This should never happen, only during decryption.
*/
throw new TlsFatalAlert(AlertDescription.internal_error);
}
return premasterSecret;
}
示例14: signData
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
/**
* sign some data using a private key and PKCS#1 v1.5 padding
*
* @param data
* the data to be signed
* @param signingKey
* the key to sign the data
* @return a signature
*/
public static byte[] signData(byte[] data, RSAKeyParameters signingKey) {
try {
byte[] hash = Encryption.getDigest(data);
PKCS1Encoding pkcs1 = new PKCS1Encoding(new RSAEngine());
pkcs1.init(true, signingKey);
return pkcs1.processBlock(hash, 0, hash.length);
} catch (InvalidCipherTextException e) {
log.log(Level.WARNING, "Common.signData(): " + e.getMessage(), e);
return null;
}
}
示例15: calculateRawSignature
import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public byte[] calculateRawSignature(AsymmetricKeyParameter privateKey, byte[] md5andsha1)
throws CryptoException
{
Signer sig = new GenericSigner(new PKCS1Encoding(new RSABlindedEngine()), new NullDigest());
sig.init(true, privateKey);
sig.update(md5andsha1, 0, md5andsha1.length);
return sig.generateSignature();
}