Top Inners Fields Constructors Methods
org.bouncycastle.openpgp.operator.jcajce

public Class JcePublicKeyKeyEncryptionMethodGenerator

extends PublicKeyKeyEncryptionMethodGenerator
Class Inheritance
Imports
java.io.IOException, java.math.BigInteger, java.security.AlgorithmParameters, .GeneralSecurityException, .InvalidKeyException, .Key, .KeyPair, .KeyPairGenerator, .Provider, .PublicKey, .SecureRandom, java.security.spec.AlgorithmParameterSpec, javax.crypto.BadPaddingException, .Cipher, .IllegalBlockSizeException, javax.crypto.spec.SecretKeySpec, org.bouncycastle.asn1.edec.EdECObjectIdentifiers, org.bouncycastle.asn1.nist.NISTObjectIdentifiers, org.bouncycastle.asn1.x509.SubjectPublicKeyInfo, org.bouncycastle.asn1.x9.X962Parameters, org.bouncycastle.bcpg.ECDHPublicBCPGKey, .MPInteger, .PublicKeyAlgorithmTags, .PublicKeyPacket, .SymmetricKeyAlgorithmTags, org.bouncycastle.jcajce.spec.HybridValueParameterSpec, .UserKeyingMaterialSpec, org.bouncycastle.jcajce.util.DefaultJcaJceHelper, .NamedJcaJceHelper, .ProviderJcaJceHelper, org.bouncycastle.openpgp.PGPException, .PGPPublicKey, .PGPUtil, org.bouncycastle.openpgp.operator.PGPPad, .PublicKeyKeyEncryptionMethodGenerator, .RFC6637Utils, org.bouncycastle.util.Arrays

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface

Field Summary

Modifier and TypeField and Description
private OperatorHelper
private JcaPGPKeyConverter
private SecureRandom
private static final byte
Inherited from org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator:
SESSION_KEY_OBFUSCATION_PROPERTYsessionKeyObfuscationuseWildcardRecipientWILDCARDWILDCARD_FINGERPRINTWILDCARD_KEYID

Constructor Summary

AccessConstructor and Description
public
JcePublicKeyKeyEncryptionMethodGenerator(PGPPublicKey
the public key to use for encryption.
key
)

Create a public key encryption method generator with the method to be based on the passed in key.

Method Summary

Modifier and TypeMethod and Description
protected byte[]
encryptSessionInfo(PGPPublicKey
recipients public key
pubKey
,
byte[]
session-key
sessionKey
,
byte
for v3: session key algorithm ID; for v6: 0
optSymAlgId
,
boolean isV3)

Implements abstract org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator.encryptSessionInfo.

Encrypt a session key using the recipients public key.

private byte[]
encryptSessionInfoWithECDHKey(KeyPair ephKP, PublicKeyPacket pubKeyPacket, PublicKey cryptoPublicKey, String keyEncryptionOID, int symmetricKeyAlgorithm, byte[] sessionInfo, String agreementName, byte symAlgId, JcePublicKeyKeyEncryptionMethodGenerator.EphPubEncoding getEncoding)

private byte[]
encryptSessionInfoWithX25519X448Key(PGPPublicKey pgpPublicKey, String algorithmName, PublicKey cryptoPublicKey, String keyEncryptionOID, int symmetricKeyAlgorithm, byte[] sessionKey, String agreementAlgorithmName, int keySize, byte optSymAlgId, boolean isV3)

Note that unlike ECDH, no checksum or padding are appended to the session key before key wrapping.

private KeyPair
getKeyPair(String algorithmName, int keySize)

private byte[]
getWrapper(int symmetricKeyAlgorithm, byte optSymAlgId, Key secret, byte[] sessionData)

public JcePublicKeyKeyEncryptionMethodGenerator
public JcePublicKeyKeyEncryptionMethodGenerator
setProvider(String providerName)

public JcePublicKeyKeyEncryptionMethodGenerator

Returns:

the current generator.
setSecureRandom
(SecureRandom
the secure random to be used.
random
)

Provide a user defined source of randomness.

Inherited from org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator:
createSessionInfoencodeEncryptedSessionInfogenerategetSessionInfosetSessionKeyObfuscationsetUseWildcardKeyIDsetUseWildcardRecipient

Field Detail

helperback to summary
private OperatorHelper helper
keyConverterback to summary
private JcaPGPKeyConverter keyConverter
randomback to summary
private SecureRandom random
X_HDRback to summary
private static final byte X_HDR

Constructor Detail

JcePublicKeyKeyEncryptionMethodGeneratorback to summary
public JcePublicKeyKeyEncryptionMethodGenerator(PGPPublicKey key)

Create a public key encryption method generator with the method to be based on the passed in key.

Parameters
key:PGPPublicKey

the public key to use for encryption.

Method Detail

encryptSessionInfoback to summary
protected byte[] encryptSessionInfo(PGPPublicKey pubKey, byte[] sessionKey, byte optSymAlgId, boolean isV3) throws PGPException

Implements abstract org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator.encryptSessionInfo.

Doc from org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator.encryptSessionInfo.

Encrypt a session key using the recipients public key.

Parameters
pubKey:PGPPublicKey

recipients public key

sessionKey:byte[]

session-key

optSymAlgId:byte

for v3: session key algorithm ID; for v6: 0

Returns:byte[]

encrypted session info

encryptSessionInfoWithECDHKeyback to summary
private byte[] encryptSessionInfoWithECDHKey(KeyPair ephKP, PublicKeyPacket pubKeyPacket, PublicKey cryptoPublicKey, String keyEncryptionOID, int symmetricKeyAlgorithm, byte[] sessionInfo, String agreementName, byte symAlgId, JcePublicKeyKeyEncryptionMethodGenerator.EphPubEncoding getEncoding) throws GeneralSecurityException, IOException, PGPException
encryptSessionInfoWithX25519X448Keyback to summary
private byte[] encryptSessionInfoWithX25519X448Key(PGPPublicKey pgpPublicKey, String algorithmName, PublicKey cryptoPublicKey, String keyEncryptionOID, int symmetricKeyAlgorithm, byte[] sessionKey, String agreementAlgorithmName, int keySize, byte optSymAlgId, boolean isV3) throws GeneralSecurityException, IOException, PGPException

Note that unlike ECDH, no checksum or padding are appended to the session key before key wrapping. Finally, note that unlike the other public-key algorithms, in the case of a v3 PKESK packet, the symmetric algorithm ID is not encrypted. Instead, it is prepended to the encrypted session key in plaintext. In this case, the symmetric algorithm used MUST be AES-128, AES-192 or AES-256 (algorithm ID 7, 8 or 9).

getKeyPairback to summary
private KeyPair getKeyPair(String algorithmName, int keySize) throws GeneralSecurityException
getWrapperback to summary
private byte[] getWrapper(int symmetricKeyAlgorithm, byte optSymAlgId, Key secret, byte[] sessionData) throws PGPException, InvalidKeyException, IllegalBlockSizeException
setProviderback to summary
public JcePublicKeyKeyEncryptionMethodGenerator setProvider(Provider provider)
setProviderback to summary
public JcePublicKeyKeyEncryptionMethodGenerator setProvider(String providerName)
setSecureRandomback to summary
public JcePublicKeyKeyEncryptionMethodGenerator setSecureRandom(SecureRandom random)

Provide a user defined source of randomness.

Parameters
random:SecureRandom

the secure random to be used.

Returns:JcePublicKeyKeyEncryptionMethodGenerator

the current generator.

org.bouncycastle.openpgp.operator.jcajce back to summary

private Interface JcePublicKeyKeyEncryptionMethodGenerator.EphPubEncoding

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public byte[]
getEphPubEncoding(byte[] publicKeyData)

Method Detail

getEphPubEncodingback to summary
public byte[] getEphPubEncoding(byte[] publicKeyData)