Gets the key length of the given {@link PublicKey}.

@param publicKey
the public key
@return the key length
490829
public static int getKeyLength(final PublicKey publicKey)
	{
		int length = -1;
		if (publicKey == null)
		{
			return length;
		}
		if (publicKey instanceof RSAPublicKey)
		{
			length = ((RSAPublicKey)publicKey).getModulus().bitLength();
		}
		if (publicKey instanceof DSAPublicKey)
		{
			length = ((DSAPublicKey)publicKey).getParams().getP().bitLength();
		}
		if (publicKey instanceof ECPublicKey)
		{
			length = ((ECPublicKey)publicKey).getParams().getCurve().getField().getFieldSize();
		}

		return length;
	}
312472
@Override
    public long getLong(@NonNull String key) {
        if (key == null) { throw new IllegalArgumentException("key cannot be null."); }

        synchronized (lock) {
            return CBLConverter.asLong(getMValue(internalDict, key), internalDict);
        }
    }
560595
public Key getKey() {
		if(key != null) {
			return key;
		} else if(keySpec != null && secretKeyFactory != null) {
			try {
				return key = secretKeyFactory.generateSecret(keySpec);
			} catch (InvalidKeySpecException e) {
				throw new RuntimeException(e);
			}
		}
		throw new IllegalStateException("Cannot produce key");
	}
1065608
public static SubjectPublicKeyInfo getSubjectPublicKeyInfo(PublicKeyParameters publicKey)
    {
        try {
            if (publicKey instanceof BcPublicKeyParameters) {
                return ((BcPublicKeyParameters) publicKey).getSubjectPublicKeyInfo();
            } else {
                return SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(getAsymmetricKeyParameter(publicKey));
            }
        } catch (IOException e) {
            // Very unlikely
            throw new IllegalArgumentException("Invalid public key, unable to get subject info.");
        }
    }
481979
long get(final long key) {
    final int probe = hashProbe(key);
    if (states[probe] > 0) {
      assert (keys[probe] == key);
      return values[probe];
    }
    return 0;
  }
812832
public static <V> int longestKeyLength(Map<String, V> map) {
    if (map.isEmpty()) {
      return 0;
    }

    return Ordering.natural().max(
        FluentIterable.from(map.keySet())
            .transform(StringUtils.lengthFunction()));
  }
409010
private File getKeyPath(final Key key) {
        KeyType keyType = null;
        if (key instanceof PrivateKey) {
            keyType = KeyType.PRIVATE;
        } else if (key instanceof PublicKey) {
            keyType = KeyType.PUBLIC;
        } else if (key instanceof SecretKey) {
            keyType = KeyType.SECRET;
        }
        return getKeyPath(keyType);
    }
609106
public PublicKey unwrapPublicKeyByKey(byte[] key,Key unwrapKey)
	{
		try {
    		if(key==null || key.length<=0 || unwrapKey==null)
    		{
    			return null;
    		}
			Cipher cipher=Cipher.getInstance(algorithm);
			//使用私钥包裹模式
			cipher.init(Cipher.UNWRAP_MODE,unwrapKey);
			return (PublicKey) cipher.unwrap(key, algorithm,Cipher.PUBLIC_KEY);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}
    	return null;
	}
1279248
public static String toBase64(final PublicKey publicKey)
	{
		final byte[] encoded = publicKey.getEncoded();
		return Base64.encodeBase64String(encoded);
	}
1256918
public static KeySize getKeySize(final PrivateKey privateKey)
	{
		int length = getKeyLength(privateKey);
		if (length == 1024)
		{
			return KeySize.KEYSIZE_1024;
		}
		if (length == 2048)
		{
			return KeySize.KEYSIZE_2048;
		}
		if (length == 4096)
		{
			return KeySize.KEYSIZE_4096;
		}
		if (length == 8192)
		{
			return KeySize.KEYSIZE_8192;
		}
		return null;
	}
307533
@Pure
	public double getLength() {
		double length  = 0;
		for (final RoadPath p : this.paths) {
			length += p.getLength();
		}
		return length;
	}
1311925
private int getLength()
    {
        if (m_length_ >= 0) {
            return m_length_;
        }
        int length = m_key_.length;
        for (int index = 0; index < length; index ++) {
            if (m_key_[index] == 0) {
                length = index;
                break;
            }
        }
        m_length_ = length;
        return m_length_;
    }
1116119
protected PGPPublicKey findPublicKey(InputStream publicKey, KeyFilter<PGPPublicKey> keyFilter ) {
    LOGGER.trace("findPublicKey(InputStream, KeyFilter<PGPPublicKey>)");
    LOGGER.trace("Public Key: {}, Key Filter: {}", publicKey == null ? "not set" : "set", keyFilter == null ? "not set" : "set");
    return retrievePublicKey(readPublicKeyRing(publicKey), keyFilter);
  }
1311054
private PublicKey getPublicKey(String MODULUS, String EXPONENT) {
        byte[] nb = base64UrlDecodeToBytes(MODULUS);
        byte[] eb = base64UrlDecodeToBytes(EXPONENT);
        BigInteger n = new BigInteger(1, nb);
        BigInteger e = new BigInteger(1, eb);

        RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec(n, e);
        try {
            PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(rsaPublicKeySpec);
            return publicKey;
        } catch (Exception ex) {
            logger.error("Exception while getting public key ", ex);
            throw new RuntimeException("Cant create public key", ex);
        }
    }
682193
@Override
  public final PublicKey lazyGetPublicKeyAnotherAjetty() throws Exception {
    if (this.publicKeyAnotherAjetty == null && this.publicKeyDir != null
      && lazyGetOurPublicKey() != null) {
      File pkDir = new File(this.publicKeyDir);
      if (pkDir.exists()) {
        File[] lstFl = pkDir.listFiles();
        if (lstFl != null && lstFl.length == 1 && lstFl[0].isFile()) {
          FileInputStream fis = null;
          try {
            fis = new FileInputStream(lstFl[0]);
            ByteArrayOutputStream baus = new ByteArrayOutputStream();
            int b;
            while ((b = fis.read()) != -1) {
              baus.write(b);
            }
            byte[] encKey = baus.toByteArray();
            X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
            KeyFactory keyFactory = KeyFactory
              .getInstance("RSA", this.cryptoProvider);
            PublicKey pkaj = keyFactory.generatePublic(pubKeySpec);
            if (!lazyGetOurPublicKey().equals(pkaj)) {
              this.publicKeyAnotherAjetty = pkaj;
            }
          } finally {
            if (fis != null) {
              try {
                fis.close();
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          }
        }
      }
    }
    return this.publicKeyAnotherAjetty;
  }
673945
public Long getLong(String key)
   {
      Long longValue = null;
      String sVal = getText(key);
      if ((sVal != null) && (sVal.length() > 0))
      {
         longValue = Long.valueOf(sVal);
      }
      return longValue;
   }
231671
public static final int getKeySize(Key key) {
        int size = -1;

        if (key instanceof Length) {
            try {
                Length ruler = (Length)key;
                size = ruler.length();
            } catch (UnsupportedOperationException usoe) {
                // ignore the exception
            }

            if (size >= 0) {
                return size;
            }
        }

        // try to parse the length from key specification
        if (key instanceof SecretKey) {
            SecretKey sk = (SecretKey)key;
            String format = sk.getFormat();
            if ("RAW".equals(format) && sk.getEncoded() != null) {
                size = (sk.getEncoded().length * 8);
            }   // Otherwise, it may be a unextractable key of PKCS#11, or
                // a key we are not able to handle.
        } else if (key instanceof RSAKey) {
            RSAKey pubk = (RSAKey)key;
            size = pubk.getModulus().bitLength();
        } else if (key instanceof ECKey) {
            ECKey pubk = (ECKey)key;
            ECParameterSpec params = pubk.getParams();
            // According to RFC 3279 section 2.3.5, EC keys are allowed
            // to inherit parameters in an X.509 certificate issuer's
            // key parameters, so the parameters may be null. The parent
            // key will be rejected if its parameters don't pass, so this
            // is okay.
            if (params != null) {
                size = params.getOrder().bitLength();
            }
        } else if (key instanceof DSAKey) {
            DSAKey pubk = (DSAKey)key;
            DSAParams params = pubk.getParams();
            // According to RFC 3279 section 2.3.2, DSA keys are allowed
            // to inherit parameters in an X.509 certificate issuer's
            // key parameters, so the parameters may be null. The parent
            // key will be rejected if its parameters don't pass, so this
            // is okay.
            if (params != null) {
                size = params.getP().bitLength();
            }
        } else if (key instanceof DHKey) {
            DHKey pubk = (DHKey)key;
            size = pubk.getParams().getP().bitLength();
        }   // Otherwise, it may be a unextractable key of PKCS#11, or
            // a key we are not able to handle.

        return size;
    }