Java 8 Key - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Key class.

This code example shows how to use the following methods:getAlgorithm, getParams, getW
    } 
     
    public JCEECPublicKey( 
        ECPublicKey     key)
    { 
        this.algorithm = key.getAlgorithm();
        this.ecSpec = key.getParams();
        this.q = EC5Util.convertPoint(this.ecSpec, key.getW(), false);
    } 
 
    JCEECPublicKey( 
        SubjectPublicKeyInfo    info)
    { 
        populateFromPubKeyInfo(info);
    } 
 
    private void populateFromPubKeyInfo(SubjectPublicKeyInfo info)
    { 
        // BEGIN android-removed 
        // if (info.getAlgorithmId().getObjectId().equals(CryptoProObjectIdentifiers.gostR3410_2001)) 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getClass, getAlgorithm, getEncoded, getFormat
 
        if (keySpec == null) {
            throw new InvalidKeySpecException("keySpec == null");
        } 
 
        if (!"EC".equals(key.getAlgorithm())) {
            throw new InvalidKeySpecException("Key must be an EC key");
        } 
 
        if (key instanceof ECPublicKey && ECPublicKeySpec.class.isAssignableFrom(keySpec)) {
            ECPublicKey ecKey = (ECPublicKey) key;
            return (T) new ECPublicKeySpec(ecKey.getW(), ecKey.getParams());
        } else if (key instanceof PublicKey && ECPublicKeySpec.class.isAssignableFrom(keySpec)) {
            final byte[] encoded = key.getEncoded();
            if (!"X.509".equals(key.getFormat()) || encoded == null) {
                throw new InvalidKeySpecException("Not a valid X.509 encoding");
            } 
            ECPublicKey ecKey = (ECPublicKey) engineGeneratePublic(new X509EncodedKeySpec(encoded));
            return (T) new ECPublicKeySpec(ecKey.getW(), ecKey.getParams());
        } else if (key instanceof ECPrivateKey

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getEncoded
  public MasterKeyData(int serialNo, SecretKey secretKey) {
    this.masterKeyRecord = Records.newRecord(MasterKey.class);
    this.masterKeyRecord.setKeyId(serialNo);
    this.generatedSecretKey = secretKey;
    this.masterKeyRecord.setBytes(ByteBuffer.wrap(generatedSecretKey
      .getEncoded()));
  } 
 
  public MasterKeyData(MasterKey masterKeyRecord, SecretKey secretKey) {
    this.masterKeyRecord = masterKeyRecord;
    this.generatedSecretKey = secretKey;
 
  } 
 
  public MasterKey getMasterKey() { 
    return this.masterKeyRecord;
  } 
 
  public SecretKey getSecretKey() {
    return this.generatedSecretKey;
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getAlgorithm, getEncoded, getFormat
    private void encodeKey( 
        Key                 key,
        DataOutputStream    dOut)
        throws IOException 
    { 
        byte[]      enc = key.getEncoded();
 
        if (key instanceof PrivateKey)
        { 
            dOut.write(KEY_PRIVATE);
        } 
        else if (key instanceof PublicKey)
        { 
            dOut.write(KEY_PUBLIC);
        } 
        else 
        { 
            dOut.write(KEY_SECRET);
        } 
     

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getClass, getAlgorithm, getEncoded, getFormat
 
        if (keySpec == null) {
            throw new InvalidKeySpecException("keySpec == null");
        } 
 
        if (!"RSA".equals(key.getAlgorithm())) {
            throw new InvalidKeySpecException("Key must be a RSA key");
        } 
 
        if (key instanceof RSAPublicKey && RSAPublicKeySpec.class.isAssignableFrom(keySpec)) {
            RSAPublicKey rsaKey = (RSAPublicKey) key;
            return (T) new RSAPublicKeySpec(rsaKey.getModulus(), rsaKey.getPublicExponent());
        } else if (key instanceof PublicKey && RSAPublicKeySpec.class.isAssignableFrom(keySpec)) {
            final byte[] encoded = key.getEncoded();
            if (!"X.509".equals(key.getFormat()) || encoded == null) {
                throw new InvalidKeySpecException("Not a valid X.509 encoding");
            } 
            RSAPublicKey rsaKey =
                    (RSAPublicKey) engineGeneratePublic(new X509EncodedKeySpec(encoded));
            return (T) new RSAPublicKeySpec(rsaKey.getModulus(), rsaKey.getPublicExponent());

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getEncoded
        } 
        else 
        { 
            try 
            { 
                byte[]  bytes = publicKey.getEncoded();
 
                publicKey = JDKKeyFactory.createPublicKeyFromDERStream(bytes);
 
                if (publicKey instanceof DSAKey)
                { 
                    param = DSAUtil.generatePublicKeyParameter(publicKey);
                } 
                else 
                { 
                    throw new InvalidKeyException("can't recognise key type in DSA based signer");
                } 
            } 
            catch (Exception e)
            { 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getEncoded
KeyGenerator kgen = KeyGenerator.getInstance("AES");  
	    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");  
	    kgen.init(m_nKeyLenBit, sr);  
	    SecretKey skey = kgen.generateKey();  
	    m_dbKeyData = skey.getEncoded();
	    Logger.I(TAG, "New key is generated");
	    if(DEBUG)
	        Logger.I(TAG, "Key: " + dumpKey(m_dbKeyData));
	} 
 
    private void writeKeyToStorage() 
    { 
        SharedPreferences settings =  ContextFactory.getContext().getSharedPreferences(m_strPrefName, Context.MODE_PRIVATE);		
        SharedPreferences.Editor editor = settings.edit();
        String strKey = Base64.encodeToString(m_dbKeyData, false);//, Base64.DEFAULT);
         
        editor.putString(m_strDBPartition, strKey );
        if (editor.commit()) {
            Logger.I(TAG, "Key is successfully saved to Shared Preferences");
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getAlgorithm
    return skf.generateSecret(keyspec);
  } 
 
  private static Cipher getCipherFromPassphrase(String passphrase, byte[] salt, int opMode) throws GeneralSecurityException {
    SecretKey key              = getKeyFromPassphrase(passphrase, salt);
    Cipher cipher              = Cipher.getInstance(key.getAlgorithm());
    cipher.init(opMode, key, new PBEParameterSpec(salt, 100));
 
    return cipher;
  } 
 
  private static byte[] encryptWithPassphrase(Context context, byte[] data, String passphrase) throws NoSuchAlgorithmException, GeneralSecurityException {
    byte[] encryptionSalt = generateSalt();
    Cipher cipher         = getCipherFromPassphrase(passphrase, encryptionSalt, Cipher.ENCRYPT_MODE);
    byte[] cipherText     = cipher.doFinal(data);
 
    save(context, "encryption_salt", encryptionSalt);
    return cipherText;
  } 
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:toString, getAlgorithm, getEncoded, getFormat
This code example shows how to use the following methods:getEncoded
    } 
 
    protected int engineGetKeySize( 
        Key     key)
    { 
        return key.getEncoded().length;
    } 
 
    protected int engineGetOutputSize( 
        int     inputLen)
    { 
        return -1; 
    } 
 
    protected AlgorithmParameters engineGetParameters()
    { 
        return null; 
    } 
 
    protected void engineSetMode( 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 Key Questions & Answers:

See Code Examples for Java 8 Key Methods: