List of usage examples for org.bouncycastle.openpgp PGPPublicKey getBitStrength
public int getBitStrength()
From source file:com.github.jpks.core.service.impl.PublicKeyReaderServiceImpl.java
License:Apache License
private PublicKeyImpl convert(final PGPPublicKey pgpPublicKey) { PublicKeyImpl key = new PublicKeyImpl(); key.setUserIds(new ArrayList<UserIdImpl>()); key.setKeyId(Long.toHexString(pgpPublicKey.getKeyID()).toUpperCase()); key.setAlgo(pgpPublicKey.getAlgorithm()); key.setKeyLen(pgpPublicKey.getBitStrength()); key.setCreationDate(pgpPublicKey.getCreationTime()); key.setMaster(pgpPublicKey.isMasterKey()); key.setRevoked(pgpPublicKey.isRevoked()); Iterator userIDs = pgpPublicKey.getUserIDs(); while (userIDs.hasNext()) { String userUd = (String) userIDs.next(); UserIdImpl userId = convert(userUd); userId.setCreationDate(pgpPublicKey.getCreationTime()); key.addUserId(userId);//from w ww . j a v a 2 s. c o m } return key; }
From source file:de.jtheuer.diki.lib.pgp.SecurityHandler.java
License:Open Source License
private void updateLocalUser() { PGPPublicKey publicKey = pgphandler.getPublickey(); /* set up pgp details for the person */ Person localAgent = connection.getUserFactory().getLocalUser(); ElmoManager manager = localAgent.getElmoManager(); LOGGER.info("Updateing PGP information for " + QNameURI.toString(localAgent.getQName())); /* check if the localAgent already is a pgp User, else designate the schema */ User pgpuser;/*from www. j av a 2 s .c om*/ if (localAgent instanceof User) { pgpuser = (User) localAgent; } else { pgpuser = manager.designateEntity(localAgent, User.class); } QNameURI pgpkey_qname = connection.getNamespaceFactory().constructNamespace("publickey"); /* fill in the public key values */ PubKey pgpkey = manager.designate(pgpkey_qname.toQName(), PubKey.class); pgpkey.setFingerprints(SimpleSet.create(PGPHandler.fingerprintOf(publicKey))); pgpkey.setHex_id(SimpleSet.create(Long.toString(publicKey.getKeyID(), 16))); pgpkey.setLengths(SimpleSet.create(BigInteger.valueOf(publicKey.getBitStrength()))); //pgpkey.setPubkeyContent(SimpleSet.create(pgphandler.exportPublicKey()); pgpkey.setIdentity(pgpuser); pgpuser.setHasKey(SimpleSet.create(pgpkey)); }
From source file:org.multibit.hd.brit.crypto.PGPUtilsTest.java
License:MIT License
@Test public void testLoadPGPPublicKeyFromASCIIArmoredFile() throws Exception { File publicKeyFile = makeFile(TEST_MATCHER_PUBLIC_KEY_FILE); log.debug("Loading public key from '" + publicKeyFile.getAbsolutePath() + "'"); FileInputStream publicKeyInputStream = new FileInputStream(publicKeyFile); PGPPublicKey publicKey = PGPUtils.readPublicKey(publicKeyInputStream); assertThat(publicKey).isNotNull();/*from w w w .ja v a 2 s . c o m*/ log.debug("Loaded PGP public key :\nAlgorithm: " + publicKey.getAlgorithm() + ", bitStrength: " + publicKey.getBitStrength() + ", fingerprint: " + Utils.HEX.encode(publicKey.getFingerprint())); }
From source file:org.pgptool.gui.encryption.implpgp.KeyFilesOperationsPgpImpl.java
License:Open Source License
private static void fillAlgorithmName(KeyInfo ret, PGPPublicKey key) throws PGPException { String alg = resolveAlgorithm(key); if (alg == null) { ret.setKeyAlgorithm("unresolved"); } else {/* w w w .ja va 2 s. c o m*/ ret.setKeyAlgorithm(alg + " " + key.getBitStrength() + "bit"); } }
From source file:org.sufficientlysecure.keychain.pgp.PgpKeyOperation.java
License:Open Source License
private static boolean checkSecurityTokenCompatibility(PGPSecretKey key, OperationLog log, int indent) { PGPPublicKey publicKey = key.getPublicKey(); int algorithm = publicKey.getAlgorithm(); if (algorithm != PublicKeyAlgorithmTags.RSA_ENCRYPT && algorithm != PublicKeyAlgorithmTags.RSA_SIGN && algorithm != PublicKeyAlgorithmTags.RSA_GENERAL) { log.add(LogType.MSG_MF_ERROR_BAD_SECURITY_TOKEN_ALGO, indent + 1); return false; }//from www.j a va 2 s. c o m // Key size must be 2048 int keySize = publicKey.getBitStrength(); if (keySize != 2048) { log.add(LogType.MSG_MF_ERROR_BAD_SECURITY_TOKEN_SIZE, indent + 1); return false; } // Secret key parts must be available if (isDivertToCard(key) || isDummy(key)) { log.add(LogType.MSG_MF_ERROR_BAD_SECURITY_TOKEN_STRIPPED, indent + 1); return false; } return true; }