java - PBKDF2WithHmacSHA1 confusing -
java - PBKDF2WithHmacSHA1 confusing -
can tell me utilize of 128*8 in code below? have written code password encryption , still don't know 128*8 doing.
this homecoming code:
67a0759ac6266ca2156555426aae10b18c34b436ea036247e6c0e16cd8d4199b9df508c32cd14e50a533ac00c071888cb8167982d9bf22a89ccd1c02a9d9c76d4e5fb5c3be91711a444a3b453c54790d5b540d7f3d0ef5798cf6a08e5acaf1b0fb445e174befd2e5b97978534aa7c22c4e404503e40f06f6832fe4a5843c9b01
the tohex() function below: think returned values in characters.
private static string tohex(byte[] array) throws nosuchalgorithmexception { biginteger bi = new biginteger(1, array); string hex = bi.tostring(16); int paddinglength = (array.length * 2) - hex.length(); if(paddinglength > 0) { homecoming string.format("%0" +paddinglength + "d", 0) + hex; }else{ homecoming hex; } } public static string encrypt(string password,string key) throws nosuchalgorithmexception, invalidkeyspecexception { int iterations = 4096; char[] chars = password.tochararray(); byte[] salt = key.getbytes(); pbekeyspec spec = new pbekeyspec(chars, salt, iterations, 128 * 8); secretkeyfactory skf = secretkeyfactory.getinstance("pbkdf2withhmacsha1"); byte[] hash = skf.generatesecret(spec).getencoded(); homecoming tohex(hash); }
the 128*8 requested key length, per documentation.
keylength
- to-be-derived key length.
it's not clear it's in bits, is. you're asking key 1024 bits long (because 128 * 8 = 1024).
you're getting hex representation 256 characters long, each of hex digit. single hex digit encodes 4 bits, you've got key 1024 bits long, asked for.
java
Comments
Post a Comment