public static byte[] derive(String P, String S, int c, int dkLen) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { int hLen = 20; if (dkLen > ((Math.pow(2, 32)) - 1) * hLen) { throw new IllegalArgumentException("derived key too long"); } else { int l = (int) Math.ceil((double) dkLen / (double) hLen); // int r = dkLen - (l-1)*hLen; for (int i = 1; i <= l; i++) { byte[] T = F(P, S, c, i); baos.write(T); } } } catch (Exception e) { throw new RuntimeException(e); } byte[] baDerived = new byte[dkLen]; System.arraycopy(baos.toByteArray(), 0, baDerived, 0, baDerived.length); return baDerived; }
public static byte[] derive(String P, String S, int c, int dkLen) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { int hLen = 20; if (dkLen > ((Math.pow(2, 32)) - 1) * hLen) { throw new IllegalArgumentException("derived key too long"); } else { int l = (int) Math.ceil((double) dkLen / (double) hLen); // int r = dkLen - (l-1)*hLen; for (int i = 1; i <= l; i++) { byte[] T = F(P, S, c, i); baos.write(T); } } } catch (Exception e) { throw new RuntimeException(e); } byte[] baDerived = new byte[dkLen]; System.arraycopy(baos.toByteArray(), 0, baDerived, 0, baDerived.length); return baDerived; }
public static byte[] derive(String P, String S, int c, int dkLen) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { int hLen = 20; if (dkLen > ((Math.pow(2, 32)) - 1) * hLen) { throw new IllegalArgumentException("derived key too long"); } else { int l = (int) Math.ceil((double) dkLen / (double) hLen); // int r = dkLen - (l-1)*hLen; for (int i = 1; i <= l; i++) { byte[] T = F(P, S, c, i); baos.write(T); } } } catch (Exception e) { throw new RuntimeException(e); } byte[] baDerived = new byte[dkLen]; System.arraycopy(baos.toByteArray(), 0, baDerived, 0, baDerived.length); return baDerived; }
public static byte[] derive(String P, String S, int c, int dkLen) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { int hLen = 20; if (dkLen > ((Math.pow(2, 32)) - 1) * hLen) { throw new IllegalArgumentException("derived key too long"); } else { int l = (int) Math.ceil((double) dkLen / (double) hLen); // int r = dkLen - (l-1)*hLen; for (int i = 1; i <= l; i++) { byte[] T = F(P, S, c, i); baos.write(T); } } } catch (Exception e) { throw new RuntimeException(e); } byte[] baDerived = new byte[dkLen]; System.arraycopy(baos.toByteArray(), 0, baDerived, 0, baDerived.length); return baDerived; }