⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 importerv3.java

📁 KeePass for J2ME is a J2ME port of KeePass Password Safe, a free, open source, light-weight and easy
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        // all bytes are zeroed for free    byte[] pad = new byte[ thisblk + nextblk ];    pad[0] = (byte)0x80;    // write length*8 to end of final block    int ix = thisblk + nextblk - 8;    Types.writeInt( data.length>>29, pad, ix );    bsw32( pad, ix );    ix += 4;    Types.writeInt( data.length<<3, pad, ix );    bsw32( pad, ix );        return pad;  }  public static void bsw32( byte[] ary, int offset ) {    byte t = ary[offset];    ary[offset] = ary[offset+3];    ary[offset+3] = t;    t = ary[offset+1];    ary[offset+1] = ary[offset+2];    ary[offset+2] = t;  }    /**   * Encrypt the master key a few times to make brute-force key-search harder   * @throws NoSuchPaddingException    * @throws NoSuchAlgorithmException    * @throws ShortBufferException   */  static byte[] transformMasterKey( byte[] pKeySeed, byte[] pKey, int rounds )      /*throws InvalidKeyException,	     IllegalBlockSizeException,	     BadPaddingException,	     NoSuchAlgorithmException,	     NoSuchPaddingException, ShortBufferException*/ {      KeePassMIDlet.logS("transformMasterKey, rounds=" + rounds);      KeePassMIDlet.logS("transformMasterKey, pkey=" + new String(Hex.encode(pKey)));	        byte[] newKey = new byte[pKey.length];      int i;            BufferedBlockCipher cipher = new BufferedBlockCipher(new AESEngine());      cipher.init(true, new KeyParameter(pKeySeed));      newKey = pKey;      for( i = 0; i < rounds; i++ )	  cipher.processBytes (newKey, 0, newKey.length, newKey, 0);      // Hash once with SHA-256      SHA256Digest md = new SHA256Digest();      md.update(newKey, 0, newKey.length );      //newKey = md.digest( newKey );      md.doFinal(newKey, 0);      return newKey;  }  /**   * Parse and save one record from binary file.   * @param buf   * @param offset   * @return If >0,    */  void readGroupField( PwGroup grp, int fieldType, byte[] buf, int offset ) {    switch( fieldType ) {      case 0x0000 :        // Ignore field        break;      case 0x0001 :        grp.groupId = Types.readInt( buf, offset );        break;      case 0x0002 :        grp.name = new String( buf, offset, Types.strlen( buf, offset ) );        break;      case 0x0003 :        grp.tCreation = Types.readTime( buf, offset );        break;      case 0x0004 :        grp.tLastMod = Types.readTime( buf, offset );        break;      case 0x0005 :        grp.tLastAccess = Types.readTime( buf, offset );        break;      case 0x0006 :        grp.tExpire = Types.readTime( buf, offset );        break;      case 0x0007 :        grp.imageId = Types.readInt( buf, offset );        break;      case 0x0008 :        grp.level = Types.readShort( buf, offset );        break;      case 0x0009 :        grp.flags = Types.readInt( buf, offset );        break;    }  }  void readEntryField( PwEntry ent, byte[] buf, int offset )      throws UnsupportedEncodingException    {    int fieldType = Types.readShort( buf, offset );    offset += 2;    int fieldSize = Types.readInt( buf, offset );    offset += 4;    switch( fieldType ) {      case 0x0000 :        // Ignore field        break;      case 0x0001 :        System.arraycopy( buf, offset, ent.uuid, 0, 16 );        break;      case 0x0002 :        ent.groupId = Types.readInt( buf, offset );        break;      case 0x0003 :        ent.imageId = Types.readInt( buf, offset );        break;      case 0x0004 :        ent.title = new String( buf, offset, Types.strlen( buf, offset ), "UTF-8" );        break;      case 0x0005 :        ent.url = new String( buf, offset, Types.strlen( buf, offset ), "UTF-8" );        break;      case 0x0006 :        ent.username = new String( buf, offset, Types.strlen( buf, offset ), "UTF-8" );        break;      case 0x0007 :        ent.setPassword( buf, offset, Types.strlen( buf, offset ) );        break;      case 0x0008 :        ent.additional = new String( buf, offset, Types.strlen( buf, offset ), "UTF-8" );        break;      case 0x0009 :        ent.tCreation = Types.readTime( buf, offset );        break;      case 0x000A :        ent.tLastMod = Types.readTime( buf, offset );        break;      case 0x000B :        ent.tLastAccess = Types.readTime( buf, offset );        break;      case 0x000C :        ent.tExpire = Types.readTime( buf, offset );        break;      case 0x000D :        ent.binaryDesc = new String( buf, offset, Types.strlen( buf, offset ), "UTF-8" );        break;      case 0x000E :        ent.setBinaryData( buf, offset, fieldSize );        break;    }  }        /**   * Attach groups to parent groups.   *    * @param groups   * @return root group.   *//*  private PwGroup fixGroups( List groups ) {    int   curLevel = -1;    Stack parents = new Stack();    PwGroup root;        root = new PwGroup();    root.level = curLevel;    parents.push( root );    for( Iterator iter = groups.iterator(); iter.hasNext(); ) {      PwGroup group = (PwGroup)iter.next();      while( group.level <= curLevel ){        parents.pop();        curLevel = ((PwGroup)parents.peek()).level;      }      if( group.level >= curLevel ) {        if( !parents.isEmpty() )          ((PwGroup)parents.peek()).children.add( group );        parents.push( group );        curLevel = group.level;      }    }    return root;  }*/  /**   * Test the BouncyCastle lib.   */  /* -- we're not using BouncyCastle  static void testRijndael_Bouncy() {    byte[] aKey = new byte[32];    byte[] aTest = new byte[16];    byte[] aRef = new byte[16];    // The Rijndael class will be tested, that's the expected ciphertext    int[] aRef_int = {        0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf, 0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89    };    int i;    // Do a quick test if the Rijndael class worked correctly    for( i = 0; i < 32; i++ ) {      aKey[i] = (byte)i;    }    for( i = 0; i < 16; i++ ) {      aTest[i] = (byte)((i << 4) | i);      aRef[i] = (byte)aRef_int[i];    }    RijndaelEngine rijndael = new RijndaelEngine( 128 );    rijndael.init( true, new KeyParameter( aKey ) );    rijndael.processBlock( aTest, 0, aTest, 0 );    if( !Arrays.equals( aTest, aRef ) )      throw new RuntimeException( "RijndaelEngine failed test" );  }*/  /**   * Test Sun's JCE.   * Note you need the "unlimited security" policy files from Sun.   * They're where you download the JDK, i.e.   * <a href="http://java.sun.com/j2se/1.5.0/download.jsp"   * >http://java.sun.com/j2se/1.5.0/download.jsp</a>   * @throws NoSuchPaddingException    * @throws NoSuchAlgorithmException    */  static void testRijndael_JCE() {    byte[] aKey = new byte[32];    byte[] aTest = new byte[16];    byte[] aRef = new byte[16];    // The Rijndael class will be tested, that's the expected ciphertext    int[] aRef_int = {        0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf, 0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89    };    int i;    // Do a quick test if the Rijndael class worked correctly    for( i = 0; i < 32; i++ ) {      aKey[i] = (byte)i;    }    for( i = 0; i < 16; i++ ) {      aTest[i] = (byte)((i << 4) | i);      aRef[i] = (byte)aRef_int[i];    }    try {	// Cipher cipher = Cipher.getInstance( "AES/ECB/NoPadding" );	BufferedBlockCipher cipher = new BufferedBlockCipher(new AESEngine());	//cipher.init( Cipher.ENCRYPT_MODE, new SecretKeySpec( aKey, "AES" ) );	cipher.init(true, new KeyParameter(aKey));	//aTest = cipher.doFinal( aTest );	cipher.processBytes(aTest, 0, aTest.length, aTest, 0);    }    catch (Exception ex) {	ex.printStackTrace();	throw new RuntimeException( "JCE failed test" );    }    if( PhoneIDUtil.compare (aTest, aRef) == false)	throw new RuntimeException( "JCE failed test" );  }}    /*NIST.gov states the following:Suppose that the length of the message, M, is l bits. Append the bit “1” to the end of themessage, followed by k zero bits, where k is the smallest, non-negative solution to the equationl +1+ k º 448mod 512 . Then append the 64-bit block that is equal to the number l expressedusing a binary representation. For example, the (8-bit ASCII) message “abc” has length8´3 = 24, so the message is padded with a one bit, then 448 - (24 +1) = 423 zero bits, and thenthe message length, to become the 512-bit padded message                              423     6401100001 01100010 01100011 1 00…00 00…011000  “a”      “b”      “c”               l = 24The length of the padded message should now be a multiple of 512 bits.*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -