Java 8 SecretKeySpec - 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 SecretKeySpec class.

This code example shows how to use the following methods:getEncoded
  } 
		 
  private SecretKeySpec deriveMacSecret(SecretKeySpec key) {
    try { 
      MessageDigest md = MessageDigest.getInstance("SHA-1");
      byte[] secret    = md.digest(key.getEncoded());
		 
      return new SecretKeySpec(secret, "HmacSHA1");
    } catch (NoSuchAlgorithmException e) {
      throw new IllegalArgumentException("SHA-1 Not Supported!",e);
    } 
  } 
	 
  private byte[] buildMessageFromCiphertext(byte[] cipherText) {
    Message message = new Message(localRecord.getCurrentKeyPair().getId(),
				  remoteRecord.getCurrentRemoteKey().getId(),
				  localRecord.getNextKeyPair().getPublicKey(),
				  sessionRecord.getCounter(),
				  cipherText, sessionRecord.getSessionVersion(), Message.SUPPORTED_VERSION);
		 

9
CodeRank
This code example shows how to use the following methods:
      byte[] encryptedMasterSecret        = verifyMac(context, encryptedAndMacdMasterSecret, passphrase);
      byte[] combinedSecrets              = decryptWithPassphrase(context, encryptedMasterSecret, passphrase);
      byte[] encryptionSecret             = getEncryptionSecret(combinedSecrets);
      byte[] macSecret                    = getMacSecret(combinedSecrets);
 
      return new MasterSecret(new SecretKeySpec(encryptionSecret, "AES"),
			      new SecretKeySpec(macSecret, "HmacSHA1"));
    } catch (GeneralSecurityException e) {
      Log.w("keyutil", e);
      return null; //XXX 
    } catch (IOException e) {
      Log.w("keyutil", e);
      return null; //XXX 
    } 
  } 
 
  public static AsymmetricMasterSecret getAsymmetricMasterSecret(Context context, MasterSecret masterSecret) {
    try { 
      PublicKey publicKey               = new PublicKey(retrieve(context, ASYMMETRIC_LOCAL_PUBLIC));
      ECPrivateKeyParameters privateKey = null;
7
CodeRank
This code example shows how to use the following methods:
     	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
     	}; 
	     
		AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
    	 
		SecretKeySpec skeySpec = new SecretKeySpec(m_dbKeyData, "AES");  
		m_encryptCipher = Cipher.getInstance("AES/CBC/NoPadding");  
		m_encryptCipher.init(Cipher.ENCRYPT_MODE, skeySpec, paramSpec);
 
		m_decryptCipher = Cipher.getInstance("AES/CBC/NoPadding");  
		m_decryptCipher.init(Cipher.DECRYPT_MODE, skeySpec, paramSpec);
		 
        Logger.T(TAG, "RhoCrypt context initialized for partition: " + szPartition);
    } 
 
    public boolean db_encrypt( String szPartition, ByteBuffer dataIn, ByteBuffer dataOut )
    { 
        try 
        { 
            initContext(szPartition);
7
CodeRank
This code example shows how to use the following methods:
        generator.init(
            PBEParametersGenerator.PKCS5PasswordToBytes(password),
            salt,
            iterationCount);
 
        return new SecretKeySpec(((KeyParameter)generator.generateDerivedParameters(PEMUtilities.getKeySize(algorithm))).getKey(), algorithm);
    } 
 
    static byte[] crypt( 
        boolean encrypt,
        String provider,
        byte[]  bytes,
        char[]  password,
        String  dekAlgName,
        byte[]  iv)
        throws IOException 
    { 
        Provider prov = null;
        if (provider != null)
        { 
7
CodeRank
This code example shows how to use the following methods:
  private Cipher getCipher(byte[] messageBytes)
      throws InvalidEncryptedSignalException, InvalidKeyException, 
             InvalidAlgorithmParameterException, NoSuchAlgorithmException, 
             NoSuchPaddingException, IOException 
  { 
    SecretKeySpec cipherKey = new SecretKeySpec(getCipherKey(), "AES");
    byte[] ivBytes          = new byte[16];
 
    if (messageBytes.length < ivBytes.length)
      throw new InvalidEncryptedSignalException("Message shorter than IV length."); 
 
    System.arraycopy(messageBytes, IV_OFFSET, ivBytes, 0, ivBytes.length);
 
    Cipher cipher      = Cipher.getInstance("AES/CBC/PKCS5Padding");
    IvParameterSpec iv = new IvParameterSpec(ivBytes);
    cipher.init(Cipher.DECRYPT_MODE, cipherKey, iv);
 
    return cipher;
  } 
 
7
CodeRank
This code example shows how to use the following methods:
      throw new OSecurityException("Error on generating key for algorithm: " + iAlgorithm, e);
    } 
  } 
 
  public SecretKey createKey(final String iAlgorithm, final byte[] iKey) throws OSecurityAccessException {
    return new SecretKeySpec(iKey, iAlgorithm);
  } 
 
  public byte[] encrypt(final String iAlgorithm, final Key iKey, final byte[] iData) throws OSecurityAccessException {
    Cipher c;
    try { 
      c = Cipher.getInstance(iAlgorithm);
      c.init(Cipher.ENCRYPT_MODE, iKey);
      return c.doFinal(iData);
    } catch (Exception e) {
      throw new OSecurityException("Error on encrypting data", e);
    } 
  } 
 
  public byte[] decrypt(final String iAlgorithm, final Key iKey, final byte[] iData) throws OSecurityAccessException {
7
CodeRank
This code example shows how to use the following methods:
		String secretKey = ERXProperties.stringForKey("er.extensions.ERXAESCipherKey");
		if (secretKey == null) {
			log.warn("er.extensions.ERXAESCipherKey not set in defaults.  Should be set before using the cipher."); 
			secretKey = "DefaultCipherKey";
		} 
		return new SecretKeySpec(secretKey.getBytes(), "AES");
	} 
} 
7
CodeRank
This code example shows how to use the following methods:
				else { 
					log.warn("ERBlowfishCipherKey is deprecated, please use er.extensions.ERXBlowfishCipherKey"); 
				} 
			} 
		} 
		return new SecretKeySpec(blowfishKey.getBytes(), "Blowfish");
	} 
} 
6
CodeRank
This code example shows how to use the following methods:
        generator.init(
            PBEParametersGenerator.PKCS5PasswordToBytes(password),
            salt,
            iterationCount);
 
        return new SecretKeySpec(((KeyParameter)generator.generateDerivedParameters(PEMUtilities.getKeySize(algorithm))).getKey(), algorithm);
    } 
 
    static byte[] crypt( 
        boolean encrypt,
        String provider,
        byte[]  bytes,
        char[]  password,
        String  dekAlgName,
        byte[]  iv)
        throws IOException 
    { 
        Provider prov = null;
        if (provider != null)
        { 
6
CodeRank
This code example shows how to use the following methods:
        { 
            throw new IllegalStateException( "Key pairs do not match!" );
        } 
 
        cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() );
        return new SecretKeySpec( cipher.doFinal( resp.getSharedSecret() ), "AES" );
    } 
 
    public static BungeeCipher getCipher(boolean forEncryption, SecretKey shared) throws GeneralSecurityException
    { 
        BungeeCipher cipher;
        if ( NativeCipher.isLoaded() ) 
        { 
            cipher = new NativeCipher();
        } else 
        { 
            cipher = new FallbackCipher();
        } 
 
        cipher.init( forEncryption, shared );
6
CodeRank

Related Java 8 SecretKeySpec Questions & Answers:

See Code Examples for Java 8 SecretKeySpec Methods: