Tabnine Logo
JuTextEncryptor.decrypt
Code IndexAdd Tabnine to your IDE (free)

How to use
decrypt
method
in
ch.inftec.ju.security.JuTextEncryptor

Best Java code snippets using ch.inftec.ju.security.JuTextEncryptor.decrypt (Showing top 8 results out of 315)

origin: ch.inftec.ju/ju-util

@Test
public void canDencryptText_usingBasicEncryptor() {
  JuTextEncryptor encryptor = JuSecurityUtils.buildEncryptor().password("secret").createTextEncryptor();
  Assert.assertEquals("String", encryptor.decrypt("8vu+etsGrzZK30MCEBjTzg=="));
}

origin: ch.inftec.ju/ju-util

@Test
public void defaultDecryptor_isAvailable_whenPassword_isSet() {
  try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) {
    ts.setProperty("ju-util.propertyChain.encryption.password", "secretPassword");
    
    Assert.assertEquals("secretVal", JuUtils.getDefaultEncryptor().decrypt("cCULeUjKiLfBwEgCOKC1g3BasxVDF85c"));
  }
}

origin: ch.inftec.ju/ju-util

@Test(expected=EncryptionOperationNotPossibleException.class)
public void throwsException_usingBasicEncryptor_withWrongPassword() {
  JuTextEncryptor encryptor = JuSecurityUtils.buildEncryptor().password("wrongSecret").createTextEncryptor();
  Assert.assertEquals("String", encryptor.decrypt("8vu+etsGrzZK30MCEBjTzg=="));
}

origin: ch.inftec.ju/ju-util

@Test
public void canEncrypt_complexCsvFile() throws Exception {
  URL srcCsv = JuUrl.resource("ch/inftec/ju/util/security/JuSecurityUtilsTest_toBeEncrypted_complex.csv");
  
  JuTextEncryptor encryptor = JuSecurityUtils.buildEncryptor().password("secret").createTextEncryptor();
  String res = JuSecurityUtils.performEncryption()
    .csvFile(srcCsv)
    .encryptor(encryptor)
    .encryptToString();
  
  List<String> lines = NewLineReader.createByString(res).getLines();
  Assert.assertEquals(3, lines.size());
  Assert.assertEquals("NormalValue;", lines.get(0));
  
  // Check first encrypted value
  Assert.assertTrue(lines.get(1).startsWith("\"ENC("));
  Assert.assertTrue(lines.get(1).endsWith(")\";another value"));
  String encryptedVal1 = new RegexUtil("\"ENC\\((.*)\\)").getMatches(lines.get(1))[0].getGroups()[0];
  Assert.assertEquals("secret(;)", encryptor.decrypt(encryptedVal1));
  
  // Check second encrypted value
  Assert.assertTrue(lines.get(2).startsWith("\"ENC("));
  Assert.assertTrue(lines.get(2).endsWith(")\";"));
  String encryptedVal2 = new RegexUtil("\"ENC\\((.*)\\)").getMatches(lines.get(2))[0].getGroups()[0];
  Assert.assertEquals("\"secret;\"", encryptor.decrypt(encryptedVal2));
  
}

origin: ch.inftec.ju/ju-util

@Test
public void canEncrypt_simpleCsvFile() throws Exception {
  URL srcCsv = JuUrl.resource("ch/inftec/ju/util/security/JuSecurityUtilsTest_toBeEncrypted.csv");
  
  JuTextEncryptor encryptor = JuSecurityUtils.buildEncryptor().password("secret").createTextEncryptor();
  String res = JuSecurityUtils.performEncryption()
    .csvFile(srcCsv)
    .encryptor(encryptor)
    .encryptToString();
  
  List<String> lines = NewLineReader.createByString(res).getLines();
  Assert.assertEquals(4, lines.size());
  Assert.assertEquals("Col1;Col2;Col3", lines.get(0));
  Assert.assertEquals(";Normal Value;", lines.get(1));
  Assert.assertEquals(";;", lines.get(2));
  Assert.assertTrue(lines.get(3).startsWith("#Come Comment;ENC(alreadyEncrypted);"));
  
  // Check encrypted value
  String encryptedVal = new RegexUtil(".*ENC\\((.*)\\)$").getMatches(lines.get(3))[0].getGroups()[0];
  Assert.assertEquals("myPrecious", encryptor.decrypt(encryptedVal));
}

origin: ch.inftec.ju/ju-util

@Test
public void canEncrypt_propertiesFile() throws Exception {
  URL srcProperties = JuUrl.resource("ch/inftec/ju/util/security/JuSecurityUtilsTest_toBeEncrypted.properties");
  
  JuTextEncryptor encryptor = JuSecurityUtils.buildEncryptor().password("secret").createTextEncryptor();
  String res = JuSecurityUtils.performEncryption()
    .propertyFile(srcProperties)
    .encryptor(encryptor)
    .encryptToString();
  
  List<String> lines = NewLineReader.createByString(res).getLines();
  Assert.assertEquals(5, lines.size());
  Assert.assertEquals("normalProperty=Normal Value", lines.get(0));
  Assert.assertEquals("", lines.get(1));
  Assert.assertEquals("# This is my little secret file...", lines.get(2));
  Assert.assertTrue(lines.get(3).startsWith("secretProperty=ENC("));
  
  // Check encrypted value
  String encryptedVal = new RegexUtil(".*ENC\\((.*)\\)").getMatches(lines.get(3))[0].getGroups()[0];
  Assert.assertEquals("myPrecious", encryptor.decrypt(encryptedVal));
  
  // Make sure already encrypted values are not changed
  Assert.assertEquals("anoterSecret=ENC(alreadyEncrypted)", lines.get(4));
}

origin: ch.inftec.ju/ju-util

@Test
public void canEncryptText_usingBasicEncryptor() {
  JuTextEncryptor encryptor = JuSecurityUtils.buildEncryptor()
      .password("secret")
      .createTextEncryptor();
  
  String encryptedString = encryptor.encrypt("String"); // The encrypted String will not be constant...
  Assert.assertNotNull(encryptor.encrypt("String"));
  Assert.assertEquals("String", encryptor.decrypt(encryptedString));
}

origin: ch.inftec.ju/ju-testing

  @Test
  public void canEncryptText_usingStrongEncryptor() {
    JuAssumeUtils.javaCryptographyExtensionInstalled();
    
    JuTextEncryptor encryptor = JuSecurityUtils.buildEncryptor()
        .strong()
        .password("secret")
        .createTextEncryptor();
    
    String encryptedString = encryptor.encrypt("String"); // The encrypted String will not be constant...
    Assert.assertNotNull(encryptor.encrypt("String"));
    Assert.assertEquals("String", encryptor.decrypt(encryptedString));
  }
}
ch.inftec.ju.securityJuTextEncryptordecrypt

Popular methods of JuTextEncryptor

  • encrypt

Popular in Java

  • Updating database using SQL prepared statement
  • getSystemService (Context)
  • putExtra (Intent)
  • setContentView (Activity)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • CodeWhisperer alternatives
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