Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.crypto.Cipher;
- import javax.crypto.spec.IvParameterSpec;
- import javax.crypto.spec.SecretKeySpec;
- import static tivitop2.Lai.hexArray;
- public class AESCBCNopading {
- public static final String KEY = "d7f8g9hk0dj2s712";
- public static final String IV = "f7h9a5d0gkvi7v6v";
- public static void main(String[] args) throws Exception {
- // d74fb44c840ebe083d59908e836a2e5c7d9963ec24c5df8ac3b9713e43e75dc92ebb0fd9e3ad9d9249d8395178debd9853c94c8ac573665925cfbab4c55d7efb7aa68725eea10fb4b85a3cc31e51704c
- // http://hlscache.fptplay.net.vn/livez/vtv1_500.stream/playlist.m3u8
- // f37249baa85d917abaf0a3a6552ec1812876f8f97a89a05f26aad35a4970df85
- // http://222.255.27.92/vtv1.m3u8
- String dataMaHoa = "http://tivi.crackgame.net/youtubefaker/Hai-co-tien-365.mp4 ";
- System.out.println("dataMaHoa:" + dataMaHoa.length());
- String dataGiaiMa = "7bffbdb21c836b1f1a3d3f697ba37d679647c47b0c6a538ef3a484bc63c68e999747105fb472b88f46557065afe57a4f0ceb11605de772bc462d644bda331430";
- String mao = "7bffbdb21c836b1f1a3d3f697ba37d679647c47bc6a538ef3a484bc63c68e999747105fb472b88f46557065afe57a4fceb11605de772bc462d644bda331430";
- System.out.println("Ma hoa: " + encrypt(dataMaHoa, KEY, IV));
- System.out.println("Giai ma: " + desEncrypt(dataGiaiMa, KEY, IV) + "mao");
- String tinh = "7bffbdb21c836b1f1a3d3f697ba37d679647c47b";
- System.out.println(tinh.length());
- }
- public static String encrypt(String data, String key, String iv) throws Exception {
- try {
- // String data = "Test String";
- // String key = "1234567812345678";
- // String iv = "1234567812345678";
- Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
- int blockSize = cipher.getBlockSize();
- byte[] dataBytes = data.getBytes();
- int plaintextLength = dataBytes.length;
- if (plaintextLength % blockSize != 0) {
- plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
- }
- byte[] plaintext = new byte[plaintextLength];
- System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
- SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
- IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
- cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
- byte[] encrypted = cipher.doFinal(plaintext);
- return bytesToHex(encrypted);
- //new sun.misc.BASE64Encoder().encode(encrypted);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- public static String desEncrypt(String data, String key, String iv) throws Exception {
- try
- {
- // String data = "2fbwW9+8vPId2/foafZq6Q==";
- // String key = "1234567812345678";
- // String iv = "1234567812345678";
- byte[] encrypted1 = hexToBytes(data);
- //new sun.misc.BASE64Decoder().decodeBuffer(data);
- Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
- SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
- IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
- cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
- byte[] original = cipher.doFinal(encrypted1);
- String originalString = new String(original);
- return originalString;
- }
- catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- public static String bytesToHex(byte[] bytes) {
- char[] hexChars = new char[bytes.length * 2];
- for (int j = 0; j < bytes.length; j++) {
- int v = bytes[j] & 0xFF;
- hexChars[j * 2] = hexArray[v >>> 4];
- hexChars[j * 2 + 1] = hexArray[v & 0x0F];
- }
- return new String(hexChars);
- }
- private static byte[] hexToBytes(String hex) {
- String HEXINDEX = "0123456789abcdef";
- int l = hex.length() / 2;
- byte data[] = new byte[l];
- int j = 0;
- for (int i = 0; i < l; i++) {
- char c = hex.charAt(j++);
- int n, b;
- n = HEXINDEX.indexOf(c);
- b = (n & 0xf) << 4;
- c = hex.charAt(j++);
- n = HEXINDEX.indexOf(c);
- b += (n & 0xf);
- data[i] = (byte) b;
- }
- return data;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment