本文整理汇总了Java中org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder类的典型用法代码示例。如果您正苦于以下问题:Java JcePBESecretKeyDecryptorBuilder类的具体用法?Java JcePBESecretKeyDecryptorBuilder怎么用?Java JcePBESecretKeyDecryptorBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JcePBESecretKeyDecryptorBuilder类属于org.bouncycastle.openpgp.operator.jcajce包,在下文中一共展示了JcePBESecretKeyDecryptorBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getX509CertificateFromPgpKeyPair
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
public static X509Certificate getX509CertificateFromPgpKeyPair( PGPPublicKey pgpPublicKey,
PGPSecretKey pgpSecretKey, String secretPwd,
String issuer, String subject, Date dateOfIssue,
Date dateOfExpiry, BigInteger serial )
throws PGPException, CertificateException, IOException
{
JcaPGPKeyConverter c = new JcaPGPKeyConverter();
PublicKey publicKey = c.getPublicKey( pgpPublicKey );
PrivateKey privateKey = c.getPrivateKey( pgpSecretKey.extractPrivateKey(
new JcePBESecretKeyDecryptorBuilder().setProvider( provider ).build( secretPwd.toCharArray() ) ) );
X509v3CertificateBuilder certBuilder =
new X509v3CertificateBuilder( new X500Name( issuer ), serial, dateOfIssue, dateOfExpiry,
new X500Name( subject ), SubjectPublicKeyInfo.getInstance( publicKey.getEncoded() ) );
byte[] certBytes = certBuilder.build( new JCESigner( privateKey, "SHA256withRSA" ) ).getEncoded();
CertificateFactory certificateFactory = CertificateFactory.getInstance( "X.509" );
return ( X509Certificate ) certificateFactory.generateCertificate( new ByteArrayInputStream( certBytes ) );
}
示例2: getPrivateKey
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
/**
* ***********************************************
*/
public static PGPPrivateKey getPrivateKey( final PGPSecretKey secretKey, final String secretPwd )
{
Preconditions.checkNotNull( secretKey );
Preconditions.checkNotNull( secretPwd );
try
{
return secretKey.extractPrivateKey(
new JcePBESecretKeyDecryptorBuilder().setProvider( provider ).build( secretPwd.toCharArray() ) );
}
catch ( Exception e )
{
LOG.error( "Unable to extract key {}: {}", secretKey.getKeyID(), e.getMessage() );
}
return null;
}
示例3: signExternal
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
public byte[] signExternal(String input) throws IOException, PGPException {
PGPSecretKey signKey = readSecretKey();
PGPPrivateKey privKey = signKey.extractPrivateKey(
new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(config.passphrase.toCharArray()));
PGPSignatureGenerator sigGenerator = new PGPSignatureGenerator(
new JcaPGPContentSignerBuilder(signKey.getPublicKey().getAlgorithm(), PGPUtil.SHA256).setProvider("BC"));
sigGenerator.init(PGPSignature.BINARY_DOCUMENT, privKey);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try (ArmoredOutputStream aOut = new ArmoredOutputStream(buffer)) {
BCPGOutputStream bOut = new BCPGOutputStream(aOut);
sigGenerator.update(input.getBytes(Charsets.UTF_8));
sigGenerator.generate().encode(bOut);
}
return buffer.toByteArray();
}
示例4: createSignature
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
private void createSignature(OutputStream out) throws Exception {
PGPSecretKey pgpSec = readSecretKey();
PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(getProvider()).build(
"sdude".toCharArray()));
PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(),
HashAlgorithmTags.SHA1).setProvider(getProvider()));
sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
BCPGOutputStream bOut = new BCPGOutputStream(out);
InputStream fIn = new ByteArrayInputStream("Test Signature".getBytes("UTF-8"));
int ch;
while ((ch = fIn.read()) >= 0) {
sGen.update((byte) ch);
}
fIn.close();
sGen.generate().encode(bOut);
}
示例5: copySecretKeyRingWithNewPassword
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
public static PGPSecretKeyRing copySecretKeyRingWithNewPassword(byte[] privateKeyData,
char[] oldPassphrase, char[] newPassphrase) throws PGPException, IOException, KonException {
// load the secret key ring
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, FP_CALC);
PGPDigestCalculatorProvider calcProv = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(calcProv)
.setProvider(PGPUtils.PROVIDER)
.build(oldPassphrase);
PGPDigestCalculator calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA256);
PBESecretKeyEncryptor encryptor = new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, calc)
.setProvider(PROVIDER).build(newPassphrase);
try {
return PGPSecretKeyRing.copyWithNewPassword(secRing, decryptor, encryptor);
} catch (PGPException ex) {
// treat this special, cause most like the decryption password was wrong
throw new KonException(KonException.Error.CHANGE_PASS_COPY, ex);
}
}
示例6: findSecretKey
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
private static PGPPrivateKey findSecretKey(
final PGPSecretKeyRingCollection keys,
final long id,
final String passphrase) {
try {
final PGPSecretKey key = keys.getSecretKey(id);
if (key != null) {
return key.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder()
.setProvider(PROVIDER)
.build(passphrase.toCharArray()));
}
} catch (Exception e) {
final String passphraseMessage = (passphrase == null) ? "null" : passphrase.length() + " character";
throw new RuntimeException("Unable to extract key " + id + " using " + passphraseMessage + " passphrase", e);
}
return null;
}
示例7: doInBackground
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
@Override
protected Void doInBackground() throws Exception
{
Main.logger.info("Neue Schlüssel werden generiert...");
PGPKeyRingGenerator pkg = RSAGen.generateKeyRingGenerator(mail, pass, this);
PGPPublicKeyRing pkr = pkg.generatePublicKeyRing();
PGPSecretKeyRing skr = pkg.generateSecretKeyRing();
Main.psk = skr.getSecretKey();
Iterator<PGPPublicKey> rIt = pkr.getPublicKeys();
// Sucht den Verschlüsselungsschlüssel
while (Main.ppk == null && rIt.hasNext())
{
PGPPublicKey temp_key = rIt.next();
if (temp_key.isEncryptionKey())
{
Main.ppk = temp_key;
break;
}
}
PBESecretKeyDecryptor secretKeyDecryptor = new JcePBESecretKeyDecryptorBuilder()
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pass);
Main.pprk = Main.psk.extractPrivateKey(secretKeyDecryptor);
setProgress(90);
// Speichern der Schlüssel
PGPSecretKeyRing pskr = pkg.generateSecretKeyRing();
ArmoredOutputStream secout = new ArmoredOutputStream(
new BufferedOutputStream(new FileOutputStream(Main.secKey)));
// Geheimer Schlüssel
pskr.encode(secout);
secout.close();
ArmoredOutputStream pubout = new ArmoredOutputStream(
new BufferedOutputStream(new FileOutputStream(Main.pubKey)));
pkr.encode(pubout);
pubout.close();
setProgress(100);
return null;
}
示例8: findSecretKey
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
private static PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyId, char[] pass)
throws PGPException, NoSuchProviderException{
PGPSecretKey pgpSecretKey = pgpSec.getSecretKey(keyId);
if (pgpSecretKey == null) return null;
return pgpSecretKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pass));
}
示例9: readPrivateKey
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
/**
* A simple routine that extracts the private key from the secret key previously set
* @param passPhrase password used to access the private key
* @return a private key
* @throws PGPException
*/
private PGPPrivateKey readPrivateKey(String passPhrase) throws PGPException{
PGPPrivateKey privateKey = secretKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passPhrase.toCharArray()));
if (privateKey != null)
return privateKey;
throw new IllegalArgumentException("No private key found in secret key");
}
示例10: signPublicKey
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
/**
* Signs a public key
*
* @param publicKeyRing a public key ring containing the single public key to sign
* @param id the id we are certifying against the public key
* @param secretKey the signing key
* @param secretKeyPassword the signing key password
*
* @return a public key ring with the signed public key
*/
public static PGPPublicKeyRing signPublicKey( PGPPublicKeyRing publicKeyRing, String id, PGPSecretKey secretKey,
String secretKeyPassword ) throws PGPException
{
try
{
PGPPublicKey oldKey = publicKeyRing.getPublicKey();
PGPPrivateKey pgpPrivKey = secretKey.extractPrivateKey(
new JcePBESecretKeyDecryptorBuilder().setProvider( provider )
.build( secretKeyPassword.toCharArray() ) );
PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(
new JcaPGPContentSignerBuilder( secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1 ) );
signatureGenerator.init( PGPSignature.DEFAULT_CERTIFICATION, pgpPrivKey );
PGPSignature signature = signatureGenerator.generateCertification( id, oldKey );
PGPPublicKey newKey = PGPPublicKey.addCertification( oldKey, signature );
PGPPublicKeyRing newPublicKeyRing = PGPPublicKeyRing.removePublicKey( publicKeyRing, oldKey );
return PGPPublicKeyRing.insertPublicKey( newPublicKeyRing, newKey );
}
catch ( Exception e )
{
//throw custom exception
throw new PGPException( "Error signing public key", e );
}
}
示例11: readPrivateKey
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
public static PGPPrivateKey readPrivateKey( InputStream is, String password ) throws PGPException, IOException
{
PGPSecretKey secretKey = readSecretKey( is );
return secretKey.extractPrivateKey(
new JcePBESecretKeyDecryptorBuilder().setProvider( "BC" ).build( password.toCharArray() ) );
}
示例12: signInline
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
public byte[] signInline(String input) throws IOException, PGPException {
PGPSecretKey signKey = readSecretKey();
PGPPrivateKey privKey = signKey.extractPrivateKey(
new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(config.passphrase.toCharArray()));
PGPSignatureGenerator sigGenerator = new PGPSignatureGenerator(
new JcaPGPContentSignerBuilder(signKey.getPublicKey().getAlgorithm(), PGPUtil.SHA256).setProvider("BC"));
sigGenerator.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, privKey);
@SuppressWarnings("unchecked")
Iterator<String> userIds = signKey.getUserIDs();
if (userIds.hasNext()) {
PGPSignatureSubpacketGenerator sigSubpacketGenerator = new PGPSignatureSubpacketGenerator();
sigSubpacketGenerator.setSignerUserID(false, userIds.next());
sigGenerator.setHashedSubpackets(sigSubpacketGenerator.generate());
}
String[] lines = input.split("\r?\n");
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try (ArmoredOutputStream aOut = new ArmoredOutputStream(buffer)) {
aOut.beginClearText(PGPUtil.SHA256);
boolean firstLine = true;
for (String line : lines) {
String sigLine = (firstLine ? "" : "\r\n") + line.replaceAll("\\s*$", "");
sigGenerator.update(sigLine.getBytes(Charsets.UTF_8));
aOut.write((line + "\n").getBytes(Charsets.UTF_8));
firstLine = false;
}
aOut.endClearText();
BCPGOutputStream bOut = new BCPGOutputStream(aOut);
sigGenerator.generate().encode(bOut);
}
return buffer.toByteArray();
}
示例13: findPrivateKeyWithkeyId
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
public static PGPPrivateKey findPrivateKeyWithkeyId(long keyid, String passphrase, PGPPassphraseAccessor passphraseAccessor,
String provider, PGPSecretKeyRingCollection pgpSec) throws PGPException {
for (Iterator<?> i = pgpSec.getKeyRings(); i.hasNext();) {
Object data = i.next();
if (data instanceof PGPSecretKeyRing) {
PGPSecretKeyRing keyring = (PGPSecretKeyRing) data;
PGPSecretKey secKey = keyring.getSecretKey(keyid);
if (secKey != null) {
if (passphrase == null && passphraseAccessor != null) {
// get passphrase from accessor // only primary/master key has user IDS
@SuppressWarnings("unchecked")
Iterator<String> userIDs = keyring.getSecretKey().getUserIDs();
while (passphrase == null && userIDs.hasNext()) {
passphrase = passphraseAccessor.getPassphrase(userIDs.next());
}
}
if (passphrase != null) {
PGPPrivateKey privateKey = secKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(provider)
.build(passphrase.toCharArray()));
if (privateKey != null) {
return privateKey;
}
}
}
}
}
return null;
}
示例14: findSecretKeysWithPrivateKeyAndUserId
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
public static List<PGPSecretKeyAndPrivateKeyAndUserId> findSecretKeysWithPrivateKeyAndUserId(Map<String, String> sigKeyUserId2Password,
String provider, PGPSecretKeyRingCollection pgpSec) throws PGPException {
List<PGPSecretKeyAndPrivateKeyAndUserId> result = new ArrayList<PGPSecretKeyAndPrivateKeyAndUserId>(sigKeyUserId2Password.size());
for (Iterator<?> i = pgpSec.getKeyRings(); i.hasNext();) {
Object data = i.next();
if (data instanceof PGPSecretKeyRing) {
PGPSecretKeyRing keyring = (PGPSecretKeyRing) data;
PGPSecretKey primaryKey = keyring.getSecretKey();
List<String> useridParts = new ArrayList<String>(sigKeyUserId2Password.keySet());
String[] foundKeyUserIdForUserIdPart = findFirstKeyUserIdContainingOneOfTheParts(useridParts, primaryKey.getPublicKey());
if (foundKeyUserIdForUserIdPart == null) {
LOG.debug("No User ID found in primary key with key ID {} containing one of the parts {}", primaryKey.getKeyID(),
useridParts);
continue;
}
LOG.debug("User ID {} found in primary key with key ID {} containing one of the parts {}", new Object[] {
foundKeyUserIdForUserIdPart[0], primaryKey.getKeyID(), useridParts });
// add all signing keys
for (Iterator<PGPSecretKey> iterKey = keyring.getSecretKeys(); iterKey.hasNext();) {
PGPSecretKey secKey = iterKey.next();
if (isSigningKey(secKey)) {
PGPPrivateKey privateKey = secKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(provider)
.build(sigKeyUserId2Password.get(foundKeyUserIdForUserIdPart[1]).toCharArray()));
if (privateKey != null) {
result.add(new PGPSecretKeyAndPrivateKeyAndUserId(secKey, privateKey, foundKeyUserIdForUserIdPart[0]));
LOG.debug("Private key with user ID {} and key ID {} added to the signing keys",
foundKeyUserIdForUserIdPart[0], Long.toString(privateKey.getKeyID()));
}
}
}
}
}
return result;
}
示例15: decrypt
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
public static final byte[] decrypt(File privring, long keyid, char[] pw, byte[] in){
if(!privring.exists() || !privring.isFile()) return null;
try {
byte[] ret = null;
FileInputStream fis = new FileInputStream(privring);
InputStream is = PGPUtil.getDecoderStream(fis);
PGPSecretKeyRingCollection ring = new PGPSecretKeyRingCollection(is);
PGPSecretKey seckey = ring.getSecretKey(keyid);
if(seckey.isMasterKey()) {
System.err.println("Someone tried to use a non-encryption key. This should never happen.");
return null;
}
PrivateKey key = new JcaPGPKeyConverter().getPrivateKey(
seckey.extractPrivateKey(
new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pw)
)
);
Cipher cipher = Cipher.getInstance(key.getAlgorithm() + "/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, key);
ret = cipher.doFinal(in);
is.close();
fis.close();
return ret;
} catch (Exception e) {
System.err.println(e.getLocalizedMessage());
return null;
}
}