Examples of SaltedSecretKey


Examples of org.syncany.crypto.SaltedSecretKey

  }

  private SaltedSecretKey createMasterKeyFromPassword(String masterPassword, byte[] masterKeySalt) throws CipherException {
    fireNotifyCreateMaster();

    SaltedSecretKey masterKey = CipherUtil.createMasterKey(masterPassword, masterKeySalt);
    return masterKey;
  }
View Full Code Here

Examples of org.syncany.crypto.SaltedSecretKey

  private void initCipherSession(String masterKeyStr, String masterKeySaltStr) {
    byte[] masterKeySalt = StringUtil.fromHex(masterKeySaltStr);
    byte[] masterKeyBytes = StringUtil.fromHex(masterKeyStr);
   
    SaltedSecretKey masterKey = new SaltedSecretKey(new SecretKeySpec(masterKeyBytes, "RAW"), masterKeySalt);   
    cipherSession = new CipherSession(masterKey);
  }
View Full Code Here

Examples of org.syncany.crypto.SaltedSecretKey

    Logging.init();
  }
 
  @Test
  public void testCipherSessionWriteKeyReuseCountOfTwo() throws Exception {
    SaltedSecretKey masterKey = createDummyMasterKey();   
    CipherSession cipherSession = new CipherSession(masterKey, 999, 2);
   
    CipherSpec cipherSpecAes128 = CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM);
    CipherSpec cipherSpecTwofish128 = CipherSpecs.getCipherSpec(CipherSpecs.TWOFISH_128_GCM);
   
    SaltedSecretKey writeSecretKey1Aes128 = cipherSession.getWriteSecretKey(cipherSpecAes128);
    SaltedSecretKey writeSecretKey2Aes128 = cipherSession.getWriteSecretKey(cipherSpecAes128);
    SaltedSecretKey writeSecretKey3Aes128 = cipherSession.getWriteSecretKey(cipherSpecAes128);
   
    SaltedSecretKey writeSecretKey1Twofish128 = cipherSession.getWriteSecretKey(cipherSpecTwofish128);
    SaltedSecretKey writeSecretKey2Twofish128 = cipherSession.getWriteSecretKey(cipherSpecTwofish128);
    SaltedSecretKey writeSecretKey3Twofish128 = cipherSession.getWriteSecretKey(cipherSpecTwofish128);
       
    assertEquals(writeSecretKey1Aes128, writeSecretKey2Aes128);
    assertNotSame(writeSecretKey1Aes128, writeSecretKey3Aes128);
   
    assertEquals(writeSecretKey1Twofish128, writeSecretKey2Twofish128);
View Full Code Here

Examples of org.syncany.crypto.SaltedSecretKey

    assertNotSame(writeSecretKey1Aes128, writeSecretKey1Twofish128);
 
 
  @Test
  public void testCipherSessionReadKeyCacheSizeOfThree() throws Exception {
    SaltedSecretKey masterKey = createDummyMasterKey();   
    CipherSession cipherSession = new CipherSession(masterKey, 2, 999);
   
    CipherSpec cipherSpecAes128 = CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM);
   
    byte[] readKeySalt1 = CipherUtil.createRandomArray(cipherSpecAes128.getKeySize());
    byte[] readKeySalt2 = CipherUtil.createRandomArray(cipherSpecAes128.getKeySize());
    byte[] readKeySalt3 = CipherUtil.createRandomArray(cipherSpecAes128.getKeySize());       
   
    SaltedSecretKey readSecretKey1Aes128 = cipherSession.getReadSecretKey(cipherSpecAes128, readKeySalt1);
    SaltedSecretKey readSecretKey2Aes128 = cipherSession.getReadSecretKey(cipherSpecAes128, readKeySalt2);
    SaltedSecretKey readSecretKey3Aes128 = cipherSession.getReadSecretKey(cipherSpecAes128, readKeySalt3);
   
    assertNotSame(readSecretKey1Aes128, readSecretKey2Aes128);
    assertNotSame(readSecretKey1Aes128, readSecretKey3Aes128);
    assertNotSame(readSecretKey2Aes128, readSecretKey3Aes128);
   
View Full Code Here

Examples of org.syncany.crypto.SaltedSecretKey

   
    // TODO [medium] This does NOT TEST the actual read cache. How to test this. The cache is completely hidden/private?!
 
 
  private SaltedSecretKey createDummyMasterKey() {
    return new SaltedSecretKey(
      new SecretKeySpec(
        StringUtil.fromHex("44fda24d53b29828b62c362529bd9df5c8a92c2736bcae3a28b3d7b44488e36e246106aa5334813028abb2048eeb5e177df1c702d93cf82aeb7b6d59a8534ff0"),
        "AnyAlgorithm"
      ),
      StringUtil.fromHex("157599349e0f1bc713afff442db9d4c3201324073d51cb33407600f305500aa3fdb31136cb1f37bd51a48f183844257d42010a36133b32b424dd02bc63b349bc")     
View Full Code Here

Examples of org.syncany.crypto.SaltedSecretKey

 
  @Test
  public void testCreateMasterKeyWithSalt() throws CipherException {
    long timeStart = System.currentTimeMillis();
   
    SaltedSecretKey masterKeyForPasswordTestAndSalt123 = CipherUtil.createMasterKey("Test", new byte[] { 1, 2, 3 });
   
    long timeEnd = System.currentTimeMillis();
    long timeDuration = timeEnd - timeStart;

    logger.log(Level.INFO, "Creating master key took "+timeDuration+"ms:");
    logger.log(Level.INFO, " - Key:  "+StringUtil.toHex(masterKeyForPasswordTestAndSalt123.getEncoded()));
    logger.log(Level.INFO, " - Salt: "+StringUtil.toHex(masterKeyForPasswordTestAndSalt123.getSalt()));
           
    assertEquals("010203", StringUtil.toHex(masterKeyForPasswordTestAndSalt123.getSalt()));
    assertEquals("44fda24d53b29828b62c362529bd9df5c8a92c2736bcae3a28b3d7b44488e36e246106aa5334813028abb2048eeb5e177df1c702d93cf82aeb7b6d59a8534ff0",
      StringUtil.toHex(masterKeyForPasswordTestAndSalt123.getEncoded()));

    assertEquals(CipherParams.MASTER_KEY_SIZE/8, masterKeyForPasswordTestAndSalt123.getEncoded().length);
    assertEquals("PBKDF2WithHmacSHA1", masterKeyForPasswordTestAndSalt123.getAlgorithm());
    assertEquals("RAW", masterKeyForPasswordTestAndSalt123.getFormat());
    
    assertTrue(timeDuration > 5000);
  }
View Full Code Here

Examples of org.syncany.crypto.SaltedSecretKey

    assertTrue(timeDuration > 5000);
  }
 
  @Test
  public void testCreateMasterKeyNoSalt() throws CipherException {
    SaltedSecretKey masterKeyForPasswordTestNoSalt1 = CipherUtil.createMasterKey("Test");
    SaltedSecretKey masterKeyForPasswordTestNoSalt2 = CipherUtil.createMasterKey("Test");
           
    logger.log(Level.INFO, "Key comparison for password 'Test':");
    logger.log(Level.INFO, "- Master key 1: "+StringUtil.toHex(masterKeyForPasswordTestNoSalt1.getEncoded()));
    logger.log(Level.INFO, "     with salt: "+StringUtil.toHex(masterKeyForPasswordTestNoSalt1.getSalt()));
    logger.log(Level.INFO, "- Master key 2: "+StringUtil.toHex(masterKeyForPasswordTestNoSalt2.getEncoded()));
    logger.log(Level.INFO, "     with salt: "+StringUtil.toHex(masterKeyForPasswordTestNoSalt2.getSalt()));
   
    assertFalse(Arrays.equals(masterKeyForPasswordTestNoSalt1.getSalt(), masterKeyForPasswordTestNoSalt2.getSalt()));
    assertFalse(Arrays.equals(masterKeyForPasswordTestNoSalt1.getEncoded(), masterKeyForPasswordTestNoSalt2.getEncoded()));
 
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.