Package org.syncany.crypto

Examples of org.syncany.crypto.SaltedSecretKey


    Logging.init();
  }
   
  @Test
  public void testCreateDerivedKeys() throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException {
    SaltedSecretKey masterKey = createDummyMasterKey();   
    CipherSpec cipherSpec = CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM);
   
    byte[] derivedKeySalt1 = new byte[] { 1, 2, 3 };
    byte[] derivedKeySalt2 = new byte[] { 1, 2, 3, 4 };

    SaltedSecretKey derivedKey1 = CipherUtil.createDerivedKey(masterKey, derivedKeySalt1, cipherSpec);
    SaltedSecretKey derivedKey2 = CipherUtil.createDerivedKey(masterKey, derivedKeySalt2, cipherSpec);
   
    logger.log(Level.INFO, "- Derived key 1: "+StringUtil.toHex(derivedKey1.getEncoded()));
    logger.log(Level.INFO, "      with salt: "+StringUtil.toHex(derivedKey1.getSalt()));
    logger.log(Level.INFO, "- Derived key 2: "+StringUtil.toHex(derivedKey2.getEncoded()));
    logger.log(Level.INFO, "      with salt: "+StringUtil.toHex(derivedKey2.getSalt()));
   
    assertEquals(128/8, derivedKey1.getEncoded().length);
    assertEquals(128/8, derivedKey2.getEncoded().length);
    assertFalse(Arrays.equals(derivedKey1.getSalt(), derivedKey2.getSalt()));
    assertFalse(Arrays.equals(derivedKey1.getEncoded(), derivedKey2.getEncoded()));       
  }
View Full Code Here


      })
    );   
 
 
  private void testEncrypt(byte[] originalData, List<CipherSpec> cipherSpecs) throws CipherException {
    SaltedSecretKey masterKey = createDummyMasterKey();
   
    byte[] ciphertext = CipherUtil.encrypt(
      new ByteArrayInputStream(originalData),
      cipherSpecs,
      masterKey
View Full Code Here

    assertTrue(Arrays.equals(originalData, plaintext))
  }
 
  @Test(expected = Exception.class)
  public void testIntegrityHeaderMagic() throws Exception {
    SaltedSecretKey masterKey = createDummyMasterKey();
   
    byte[] originalPlaintext = TestFileUtil.createRandomArray(50);
   
    byte[] ciphertext = CipherUtil.encrypt(
      new ByteArrayInputStream(originalPlaintext),
View Full Code Here

    fail("TEST FAILED: Ciphertext was altered without exception.");
 
 
  @Test(expected = Exception.class)
  public void testIntegrityHeaderVersion() throws Exception {
    SaltedSecretKey masterKey = createDummyMasterKey();
   
    byte[] originalPlaintext = TestFileUtil.createRandomArray(50);
   
    byte[] ciphertext = CipherUtil.encrypt(
      new ByteArrayInputStream(originalPlaintext),
View Full Code Here

    fail("TEST FAILED: Ciphertext was altered without exception.");
 
 
  @Test(expected = Exception.class)
  public void testIntegrityHeaderCipherSpecId() throws Exception {
    SaltedSecretKey masterKey = createDummyMasterKey();
   
    byte[] originalPlaintext = TestFileUtil.createRandomArray(50);
   
    byte[] ciphertext = CipherUtil.encrypt(
      new ByteArrayInputStream(originalPlaintext),
View Full Code Here

    fail("TEST FAILED: Ciphertext was altered without exception.");
 
 
  @Test(expected = Exception.class)
  public void testIntegrityHeaderCipherSalt() throws Exception {
    SaltedSecretKey masterKey = createDummyMasterKey();
    
    byte[] originalPlaintext = TestFileUtil.createRandomArray(50);
   
    byte[] ciphertext = CipherUtil.encrypt(
      new ByteArrayInputStream(originalPlaintext),
View Full Code Here

    fail("TEST FAILED: Ciphertext was altered without exception.");
 
 
  @Test(expected = Exception.class)
  public void testIntegrityHeaderCipherIV() throws Exception {
    SaltedSecretKey masterKey = createDummyMasterKey();
   
    byte[] originalPlaintext = TestFileUtil.createRandomArray(50);
   
    byte[] ciphertext = CipherUtil.encrypt(
      new ByteArrayInputStream(originalPlaintext),
View Full Code Here

    fail("TEST FAILED: Ciphertext was altered without exception.");
 
 
  @Test(expected = CipherException.class)
  public void testIntegrityAesGcmCiphertext() throws Exception {
    SaltedSecretKey masterKey = createDummyMasterKey();
   
    byte[] originalPlaintext = TestFileUtil.createRandomArray(50);
   
    byte[] ciphertext = CipherUtil.encrypt(
      new ByteArrayInputStream(originalPlaintext),
View Full Code Here

    fail("TEST FAILED: Ciphertext was altered without exception.");
 
 
  @Test(expected = Exception.class)
  public void testIntegrityTwofishGcmCiphertext() throws Exception {
    SaltedSecretKey masterKey = createDummyMasterKey();
   
    byte[] originalPlaintext = TestFileUtil.createRandomArray(50);
   
    byte[] ciphertext = CipherUtil.encrypt(
      new ByteArrayInputStream(originalPlaintext),
View Full Code Here

   
    fail("TEST FAILED: Ciphertext was altered without exception.");
 

  private SaltedSecretKey createDummyMasterKey() {
    return new SaltedSecretKey(
      new SecretKeySpec(
        StringUtil.fromHex("44fda24d53b29828b62c362529bd9df5c8a92c2736bcae3a28b3d7b44488e36e246106aa5334813028abb2048eeb5e177df1c702d93cf82aeb7b6d59a8534ff0"),
        "AnyAlgorithm"
      ),
      StringUtil.fromHex("157599349e0f1bc713afff442db9d4c3201324073d51cb33407600f305500aa3fdb31136cb1f37bd51a48f183844257d42010a36133b32b424dd02bc63b349bc")     
View Full Code Here

TOP

Related Classes of org.syncany.crypto.SaltedSecretKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.