Tabnine Logo
DefaultCipherService
Code IndexAdd Tabnine to your IDE (free)

How to use
DefaultCipherService
in
org.apache.deltaspike.core.impl.crypto

Best Java code snippets using org.apache.deltaspike.core.impl.crypto.DefaultCipherService (Showing top 12 results out of 315)

origin: apache/deltaspike

  @Override
  public String decrypt(String encryptedValue, String masterSalt)
  {
    return cipherService.decrypt(encryptedValue, masterSalt);
  }
}
origin: apache/deltaspike

@Override
public String encrypt(String cleartext, String masterSalt)
{
  return cipherService.encrypt(cleartext, masterSalt);
}
origin: apache/deltaspike

@Override
public void setMasterHash(String masterPassword, String masterSalt, boolean overwrite)
  throws IOException
{
  cipherService.setMasterHash(masterPassword, masterSalt, overwrite);
}
origin: apache/deltaspike

public String encrypt(String cleartext, String masterSalt)
{
  return byteToHex(aesEncrypt(cleartext, getMasterKey(masterSalt)));
}
origin: apache/deltaspike

public String decrypt(String encryptedValue, String masterSalt)
{
  return aesDecrypt(hexToByte(encryptedValue), getMasterKey(masterSalt));
}
origin: apache/deltaspike

@Test
public void testMasterPwdEncryption() throws Exception
{
  DefaultCipherService cipherService = new DefaultCipherService();
  String masterSalt = "deltaspike-test-salt";
  cipherService.setMasterHash("newMasterPwd", masterSalt, true);
  String cleartext = "my cleartext sentence";
  String encrypted = cipherService.encrypt(cleartext, masterSalt);
  String decrypted = cipherService.decrypt(encrypted, masterSalt);
  Assert.assertEquals(cleartext, decrypted);
}
origin: apache/deltaspike

protected String getMasterKey(String masterSalt)
{
  File masterFile = getMasterFile();
  if (!masterFile.exists())
  {
    throw new IllegalStateException("Could not find master.hash file. Create a master password first!");
  }
  try
  {
    String saltHash = byteToHex(secureHash(masterSalt));
    String saltKey = byteToHex(secureHash(saltHash));
    Properties keys = loadProperties(masterFile.toURI().toURL());
    String encryptedMasterKey = (String) keys.get(saltKey);
    if (encryptedMasterKey == null)
    {
      throw new IllegalStateException("Could not find master key for hash " + saltKey +
        ". Create a master password first!");
    }
    return aesDecrypt(hexToByte(encryptedMasterKey), saltHash);
  }
  catch (MalformedURLException e)
  {
    throw new RuntimeException(e);
  }
}
origin: apache/deltaspike

DefaultCipherService defaultCipherService = new DefaultCipherService();
  String masterSaltHash = defaultCipherService.setMasterHash(masterPwd, masterSalt, overwrite);
  String encrypted = defaultCipherService.encrypt(plaintext, masterSalt);
  System.out.println("Encrypted value: " + encrypted);
origin: apache/deltaspike

public String setMasterHash(String masterPassword, String masterSalt, boolean overwrite)
  throws IOException
{
  File masterFile = getMasterFile();
  if (!masterFile.getParentFile().exists())
  {
    if (!masterFile.getParentFile().mkdirs())
    {
      throw new IOException("Can not create directory " + masterFile.getParent());
    }
  }
  String saltHash = byteToHex(secureHash(masterSalt));
  String saltKey = byteToHex(secureHash(saltHash));
  String encrypted = byteToHex(aesEncrypt(byteToHex(secureHash(masterPassword)), saltHash));
  Properties keys = new Properties();
  if (masterFile.exists())
  {
    keys = loadProperties(masterFile.toURI().toURL());
  }
  if (keys.get(saltKey) != null && !overwrite)
  {
    throw new IllegalStateException("MasterKey for hash " + saltKey +
      " already exists. Forced overwrite option needed");
  }
  keys.put(saltKey, encrypted);
  keys.store(new FileOutputStream(masterFile), null);
  return saltKey;
}
origin: apache/deltaspike

@Test
public void testMasterKeyOverwrite() throws Exception {
  DefaultCipherService cipherService = new DefaultCipherService();
  String masterSalt = "deltaspike-test-salt";
  cipherService.setMasterHash("newMasterPwd", masterSalt, true);
  try {
    cipherService.setMasterHash("newMasterPwd", masterSalt, false);
    Assert.fail();
  }
  catch (Exception e) {
    // todo: how to log exception properly
    // System.out.println("expected: " + e);
  }
}
origin: apache/deltaspike

/**
 * performs an AES encryption of the given text with the given password key
 */
public byte[] aesEncrypt(String valueToEncrypt, String key)
{
  try
  {
    SecretKeySpec secretKeySpec = getSecretKeySpec(key);
    Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
    cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
    return cipher.doFinal(valueToEncrypt.getBytes(UTF_8));
  }
  catch (Exception e)
  {
    throw new RuntimeException(e);
  }
}
origin: apache/deltaspike

/**
 * performs an AES decryption of the given text with the given key key
 */
public String aesDecrypt(byte[] encryptedValue, String key)
{
  try
  {
    SecretKeySpec secretKeySpec = getSecretKeySpec(key);
    Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
    cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
    return new String(cipher.doFinal(encryptedValue), UTF_8);
  }
  catch (Exception e)
  {
    throw new RuntimeException(e);
  }
}
org.apache.deltaspike.core.impl.cryptoDefaultCipherService

Javadoc

handle Encryption

Most used methods

  • <init>
  • decrypt
  • encrypt
  • setMasterHash
  • aesDecrypt
    performs an AES decryption of the given text with the given key key
  • aesEncrypt
    performs an AES encryption of the given text with the given password key
  • byteToHex
  • getMasterFile
  • getMasterKey
  • getSecretKeySpec
  • hexToByte
  • loadProperties
    Copied over from PropertyFileUtils to avoid the need for having the api on the classpath when using
  • hexToByte,
  • loadProperties,
  • secureHash

Popular in Java

  • Creating JSON documents from java classes using gson
  • compareTo (BigDecimal)
  • getExternalFilesDir (Context)
  • scheduleAtFixedRate (Timer)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • JFileChooser (javax.swing)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now