genkey

16:35:58.443 INFO  jd.cli.Main - Decompiling genkey.jar
package com.wowza.util;

import java.io.PrintStream;
import java.nio.ByteBuffer;

public class BufferUtils
{
  private static final String[] hexadecimal = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
  private static final int[] CRC32INIT = {
    0, -1222786812, 1849393673, -651803891, -596245485, 1802224919, 
    -1303542246, 89147166, -1192425434, 267438370, -690582993, 1640713003, 
    1687882805, -746140367, 178294332, -1111666888, 1893405004, -943271864, 
    518034245, -1443016127, -1397942945, 464573531, -1030318250, 1972065874, 
    -935978646, 2133579886, -1509057693, 286284391, 339746169, -1554129795, 
    2054922096, -848929164, -524934248, 1470882460, -1903320687, 965763221, 
    1019225995, -1948391793, 1392223618, -437885818, 1482369982, -280565062, 
    912304567, -2122487629, -2077413459, 858844841, -367612508, 1561029792, 
    -1871891756, 661713872, -27873059, 1229681113, 1276851911, -83429437, 
    572568782, -1791134262, 679492338, -1617036298, 1186707707, -240748033, 
    -185188639, 1139539941, -1697792792, 768638444, 2003863092, -1066580176, 
    424346685, -1370045127, -1425636825, 471548707, -985858002, 1914749226, 
    -811758062, 2021674774, -1582953445, 381406495, 334203393, -1527362811, 
    2110785544, -892483316, 128685944, -1330227588, 1771050353, -561130379, 
    -606235797, 1824543343, -1243213470, 50057318, -1085890722, 140205658, 
    -780329641, 1717623891, 1664129869, -735225271, 218831172, -1172907968, 
    -1748589140, 551249064, -100849755, 1323361953, 1269866943, -55746373, 
    629875638, -1835605326, 791391626, -1741263730, 1091579779, -166859129, 
    -211965543, 1145071773, -1654248560, 712764052, -417483552, 1342207460, 
    -1993984279, 1044117485, 996913395, -1938394633, 1431319290, -498207746, 
    1609612486, -387088958, 835403471, -2032730165, -2088322859, 882604497, 
    -306365732, 1520499672, -287306647, 1509805421, -2133094816, 935743332, 
    848693370, -2054436482, 1554877043, -340767881, 1443693647, -518994613, 
    943097414, -1892989118, -1971650468, 1030144344, -465534379, 1398621009, 
    -1640293083, 690412577, -268394708, 1193106984, 1112348982, -179251150, 
    745970495, -1687463365, 651564291, -1848912889, 1223530250, -1026546, 
    -90173168, 1304285204, -1801743591, 596005405, 240529393, -1186205963, 
    1617800696, -680497924, -769643550, 1698556646, -1139037717, 184969455, 
    -1229248553, 27715283, -662657570, 1872585946, 1791828932, -573513024, 
    83272141, -1276419895, 2123185853, -913244231, 280411316, -1481933392, 
    -1560593746, 367459242, -859785049, 2078112163, -966773093, 1904080799, 
    -1470385006, 524711318, 437662344, -1391725684, 1949151361, -1020235387, 
    -1718580643, 781011801, -139786156, 1085720912, 1172737614, -218411190, 
    735906887, -1665086141, 561873531, -1772076161, 1329987698, -128204426, 
    -49576344, 1242974060, -1825569695, 606979429, -380921071, 1582717461, 
    -2022696680, 812505116, 893230850, -2111807994, 1527127307, -333718513, 
    1369871159, -423931341, 1067258174, -2004824006, -1915709660, 986535456, 
    -471132883, 1425462313, 2032576965, -834967359, 387787724, -1610552632, 
    -1521439274, 307064018, -882167841, 2088169179, -1043619357, 1993760999, 
    -1343216662, 418243310, 498968048, -1432328972, 1938171897, -996415747, 
    167622793, -1092585075, 1741044352, -790889596, -712262502, 1654029726, 
    -1146077549, 212729751, -1324306257, 101544363, -550817114, 1748431778, 
    1835447484, -629443144, 56440501, -1270810703, 1 };
  
  public static String encodeHexString(byte[] bytes)
  {
    String ret = "";
    for (int i = 0; i < bytes.length; i++)
    {
      int low = bytes[i] & 0xF;
      int high = (bytes[i] & 0xF0) >> 4;
      ret = ret + hexadecimal[high];
      ret = ret + hexadecimal[low];
    }
    return ret;
  }
  
  public static byte[] decodeHexString(String hexStr)
  {
    byte[] ret = (byte[])null;
    try
    {
      if (hexStr.length() % 2 == 1) {
        hexStr = "0" + hexStr;
      }
      ret = new byte[hexStr.length() / 2];
      int index = 0;
      int len = hexStr.length();
      do
      {
        String val = hexStr.substring(index, index + 2);
        ret[(index / 2)] = ((byte)(Integer.parseInt(val, 16) & 0xFF));
        index += 2;
      } while (index < len);
    }
    catch (Exception e)
    {
      System.out.println("BufferUtils.decodeHexString: " + e.toString());
    }
    return ret;
  }
  
  public static String byteArrayToString(byte[] b)
  {
    return byteArrayToString(b, 0, b.length);
  }
  
  public static String byteArrayToString(byte[] b, int offset, int count)
  {
    String ret = null;
    try
    {
      byte[] tmp = new byte[count];
      System.arraycopy(b, offset, tmp, 0, count);
      ret = new String(tmp, "UTF-8");
    }
    catch (Exception localException) {}
    return ret;
  }
  
  public static long byteArrayToLong(byte[] b)
  {
    long l = 0L;
    
    l |= b[0] & 0xFF;
    l <<= 8;
    l |= b[1] & 0xFF;
    l <<= 8;
    l |= b[2] & 0xFF;
    l <<= 8;
    l |= b[3] & 0xFF;
    l <<= 8;
    l |= b[4] & 0xFF;
    l <<= 8;
    l |= b[5] & 0xFF;
    l <<= 8;
    l |= b[6] & 0xFF;
    l <<= 8;
    l |= b[7] & 0xFF;
    
    return l;
  }
  
  public static long byteArrayToLong(byte[] b, int offset)
  {
    long l = 0L;
    
    l |= b[(offset + 0)] & 0xFF;
    l <<= 8;
    l |= b[(offset + 1)] & 0xFF;
    l <<= 8;
    l |= b[(offset + 2)] & 0xFF;
    l <<= 8;
    l |= b[(offset + 3)] & 0xFF;
    l <<= 8;
    l |= b[(offset + 4)] & 0xFF;
    l <<= 8;
    l |= b[(offset + 5)] & 0xFF;
    l <<= 8;
    l |= b[(offset + 6)] & 0xFF;
    l <<= 8;
    l |= b[(offset + 7)] & 0xFF;
    
    return l;
  }
  
  public static long byteArrayToLong(byte[] b, int offset, int count)
  {
    return byteArrayToLong(b, offset, count, false);
  }
  
  public static long byteArrayToLong(byte[] b, int offset, int count, boolean isReverse)
  {
    long l = 0L;
    for (int i = 0; i < count; i++)
    {
      if (i > 0) {
        l <<= 8;
      }
      if (isReverse) {
        l |= b[(offset + (count - (i + 1)))] & 0xFF;
      } else {
        l |= b[(offset + i)] & 0xFF;
      }
    }
    return l;
  }
  
  public static int byteArrayToInt(byte[] b)
  {
    return b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | b[3] & 0xFF;
  }
  
  public static int byteArrayToInt(byte[] b, int offset)
  {
    return b[(offset + 0)] << 24 | (b[(offset + 1)] & 0xFF) << 16 | (b[(offset + 2)] & 0xFF) << 8 | b[(offset + 3)] & 0xFF;
  }
  
  public static int byteArrayToInt(byte[] b, int offset, int count)
  {
    return byteArrayToInt(b, offset, count, false);
  }
  
  public static int byteArrayToInt(byte[] b, int offset, int count, boolean isReverse)
  {
    int l = 0;
    for (int i = 0; i < count; i++)
    {
      if (i > 0) {
        l <<= 8;
      }
      if (isReverse) {
        l |= b[(offset + (count - (i + 1)))] & 0xFF;
      } else {
        l |= b[(offset + i)] & 0xFF;
      }
    }
    return l;
  }
  
  public static int byteArrayToShort(byte[] b)
  {
    return byteArrayToShort(b, 0, 2, false);
  }
  
  public static int byteArrayToShort(byte[] b, int offset)
  {
    return byteArrayToShort(b, offset, 2, false);
  }
  
  public static int byteArrayToShort(byte[] b, int offset, int count)
  {
    return byteArrayToShort(b, offset, count, false);
  }
  
  public static int byteArrayToShort(byte[] b, int offset, int count, boolean isReverse)
  {
    short l = 0;
    for (int i = 0; i < count; i++)
    {
      if (i > 0) {
        l = (short)(l << 8);
      }
      if (isReverse) {
        l = (short)(l | b[(offset + (count - (i + 1)))] & 0xFF);
      } else {
        l = (short)(l | b[(offset + i)] & 0xFF);
      }
    }
    return l;
  }
  
  public static byte[] intToByteArray(int value)
  {
    return intToByteArray(value, 4);
  }
  
  public static byte[] intToByteArray(int value, int size)
  {
    byte[] ret = new byte[size];
    for (int i = 0; i < Math.min(size, 4); i++)
    {
      int index = size - i - 1;
      ret[index] = ((byte)(value & 0xFF));
      value >>= 8;
      if (value == 0) {
        break;
      }
    }
    return ret;
  }
  
  public static void intToByteArray(int value, byte[] buffer, int offset, int size)
  {
    intToByteArray(value, buffer, offset, size, false);
  }
  
  public static void intToByteArray(int value, byte[] buffer, int offset, int size, boolean isReverse)
  {
    for (int i = 0; i < Math.min(size, 4); i++)
    {
      int index = isReverse ? i : size - (i + 1);
      buffer[(offset + index)] = ((byte)(value & 0xFF));
      value >>= 8;
    }
  }
  
  public static byte[] longToByteArray(long value)
  {
    return longToByteArray(value, 8);
  }
  
  public static byte[] longToByteArray(long value, int size)
  {
    byte[] ret = new byte[size];
    for (int i = 0; i < Math.min(size, 8); i++)
    {
      int index = size - i - 1;
      ret[index] = ((byte)(int)(value & 0xFF));
      value >>= 8;
      if (value == 0L) {
        break;
      }
    }
    return ret;
  }
  
  public static void longToByteArray(long value, byte[] buffer, int offset, int size)
  {
    for (int i = 0; i < Math.min(size, 8); i++)
    {
      int index = size - i - 1;
      buffer[(offset + index)] = ((byte)(int)(value & 0xFF));
      value >>= 8;
    }
  }
  
  public static void longToByteArray(long value, byte[] buffer, int offset, int size, boolean isReverse)
  {
    for (int i = 0; i < Math.min(size, 8); i++)
    {
      int index = isReverse ? i : size - (i + 1);
      buffer[(offset + index)] = ((byte)(int)(value & 0xFF));
      value >>= 8;
    }
  }
  
  public static int getUnsignedShort(ByteBuffer buffer)
  {
    byte[] tmp = new byte[2];
    buffer.get(tmp);
    return byteArrayToInt(tmp, 0, 2);
  }
  
  public static int doCRC32(int crc, byte[] buffer, int offset, int len)
  {
    for (int i = 0; i < len; i++)
    {
      int index = (crc ^ buffer[(i + offset)]) & 0xFF;
      crc = CRC32INIT[index] ^ crc >> 8 & 0xFFFFFF;
    }
    return crc;
  }
}

/* Location:
 * Qualified Name:     com.wowza.util.BufferUtils
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package main;

import com.wowza.util.BufferUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class Main
{
  public static final String KEYPARAMPREFIX = "cupertinostreaming-aes128-";
  
  public static void main(String[] args)
  {
    if ((args.length < 2) || (args.length > 3))
    {
      System.out.println("");
      System.out.println("genkey is used to generate an encryption key file for encrypted iOS streaming.");
      System.out.println("The file generated by this tool must to be copied to the [install-dir]/keys folder");
      System.out.println("");
      System.out.println("Usage:");
      System.out.println("genkey target stream-name [url]");
      System.out.println("");
      System.out.println("target: streaming target (iOS only at this time)");
      System.out.println("stream-name: name of stream (key file will be [stream-name].key)");
      System.out.println("url: URL from which the encryption key will be requested (optional)");
      System.out.println("     Add ?{sessionid} to the end of the url to receive the");
      System.out.println("     sessionId as part of the key file request.");
      System.out.println("");
      System.out.println("Examples:");
      System.out.println("");
      System.out.println("genkey iOS myStream.sdp");
      System.out.println("");
      System.out.println("genkey iOS myStream.sdp https://mycompany.com/myStream.sdp/encryption.key?{sessionid}");
      System.out.println("");
      return;
    }
    String target = "iOS";
    String streamName = null;
    String url = null;
    String key = null;
    if (args.length > 0) {
      target = args[0].trim();
    }
    if (args.length > 1) {
      streamName = args[1].trim();
    }
    if (args.length > 2) {
      url = args[2].trim();
    }
    try
    {
      KeyGenerator kgen = KeyGenerator.getInstance("AES");
      kgen.init(128);
      SecretKey skey = kgen.generateKey();
      byte[] raw = skey.getEncoded();
      key = BufferUtils.encodeHexString(raw);
      System.out.println("");
      System.out.println("cupertinostreaming-aes128-key: " + key);
      if (url != null) {
        System.out.println("cupertinostreaming-aes128-url: " + url);
      }
      System.out.println("");
      
      PrintWriter pw = new PrintWriter(new FileOutputStream(new File(streamName + ".key"), false));
      pw.println("cupertinostreaming-aes128-key: " + key);
      if (url != null) {
        pw.println("cupertinostreaming-aes128-url: " + url);
      }
      pw.close();
      System.out.println("Key file generated: " + streamName + ".key");
      System.out.println("Copy file to: [install-dir]/keys");
      System.out.println("");
    }
    catch (Exception e)
    {
      System.out.println("genkey: Error: " + e.toString());
    }
  }
}

/* Location:
 * Qualified Name:     main.Main
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd