@@ -44,11 +44,6 @@ public class Pubnub {
4444 private String SUBSCRIBE_KEY = "" ;
4545 private String SECRET_KEY = "" ;
4646 public String CIPHER_KEY = "" ;
47- public String INITIALIZATION_VECTOR = "" ;
48-
49- /** The default initialization vector. */
50- private static final String DEFAULT_IV = "0123456789012345" ;
51-
5247 private boolean SSL = false ;
5348 private String sessionUUID = "" ;
5449 private String parameters = "" ;
@@ -74,34 +69,10 @@ private class ChannelStatus {
7469 * @param String
7570 * Cipher Key.
7671 * @param boolean SSL Enabled.
77- *
78- * @param initialization_vector The initialization vector used to create the cipher.
79- */
80- public Pubnub (String publish_key , String subscribe_key , String secret_key ,
81- String cipher_key , boolean ssl_on , String initialization_vector ) {
82- this .init (publish_key , subscribe_key , secret_key , cipher_key , ssl_on , initialization_vector );
83- }
84-
85- /**
86- * PubNub 3.1 with Cipher Key
87- *
88- * Prepare PubNub State.
89- *
90- * @param String
91- * Publish Key.
92- * @param String
93- * Subscribe Key.
94- * @param String
95- * Secret Key.
96- * @param String
97- * Cipher Key.
98- * @param boolean SSL Enabled.
99- *
100- * .
10172 */
10273 public Pubnub (String publish_key , String subscribe_key , String secret_key ,
103- String cipher_key , boolean ssl_on ) {
104- this .init (publish_key , subscribe_key , secret_key , cipher_key , ssl_on , DEFAULT_IV );
74+ String cipher_key , boolean ssl_on ) {
75+ this .init (publish_key , subscribe_key , secret_key , cipher_key , ssl_on );
10576 }
10677
10778 /**
@@ -119,7 +90,7 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key,
11990 */
12091 public Pubnub (String publish_key , String subscribe_key , String secret_key ,
12192 boolean ssl_on ) {
122- this .init (publish_key , subscribe_key , secret_key , "" , ssl_on , "" );
93+ this .init (publish_key , subscribe_key , secret_key , "" , ssl_on );
12394 }
12495
12596 /**
@@ -133,7 +104,7 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key,
133104 * Subscribe Key.
134105 */
135106 public Pubnub (String publish_key , String subscribe_key ) {
136- this .init (publish_key , subscribe_key , "" , "" , false , "" );
107+ this .init (publish_key , subscribe_key , "" , "" , false );
137108 }
138109
139110 /**
@@ -149,7 +120,7 @@ public Pubnub(String publish_key, String subscribe_key) {
149120 * Secret Key.
150121 */
151122 public Pubnub (String publish_key , String subscribe_key , String secret_key ) {
152- this .init (publish_key , subscribe_key , secret_key , "" , false , "" );
123+ this .init (publish_key , subscribe_key , secret_key , "" , false );
153124 }
154125
155126 /**
@@ -166,15 +137,13 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key) {
166137 * @param String
167138 * Cipher Key.
168139 * @param boolean SSL Enabled.
169- * @param String Initialization vector used to configure the cipher.
170140 */
171141 public void init (String publish_key , String subscribe_key ,
172- String secret_key , String cipher_key , boolean ssl_on , String initialization_vector ) {
142+ String secret_key , String cipher_key , boolean ssl_on ) {
173143 this .PUBLISH_KEY = publish_key ;
174144 this .SUBSCRIBE_KEY = subscribe_key ;
175145 this .SECRET_KEY = secret_key ;
176146 this .CIPHER_KEY = cipher_key ;
177- this .INITIALIZATION_VECTOR = initialization_vector ;
178147 this .SSL = ssl_on ;
179148
180149 if (this .sessionUUID .equals ("" ))
@@ -223,7 +192,7 @@ public JSONArray publish(HashMap<String, Object> args) {
223192 JSONObject obj = (JSONObject ) message ;
224193 if (this .CIPHER_KEY .length () > 0 ) {
225194 // Encrypt Message
226- PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
195+ PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY );
227196 message = pc .encrypt (obj );
228197 } else {
229198 message = obj ;
@@ -233,7 +202,7 @@ public JSONArray publish(HashMap<String, Object> args) {
233202 String obj = (String ) message ;
234203 if (this .CIPHER_KEY .length () > 0 ) {
235204 // Encrypt Message
236- PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
205+ PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY );
237206 try {
238207 message = pc .encrypt (obj );
239208 } catch (Exception e ) {
@@ -249,7 +218,7 @@ public JSONArray publish(HashMap<String, Object> args) {
249218
250219 if (this .CIPHER_KEY .length () > 0 ) {
251220 // Encrypt Message
252- PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
221+ PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY );
253222 message = pc .encryptJSONArray (obj );
254223 } else {
255224 message = obj ;
@@ -468,7 +437,7 @@ private void _subscribe(HashMap<String, Object> args) {
468437
469438 if (this .CIPHER_KEY .length () > 0 ) {
470439 // Decrypt Message
471- PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
440+ PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY );
472441 message = pc .decrypt (message );
473442 }
474443 if (callback != null )
@@ -479,7 +448,7 @@ private void _subscribe(HashMap<String, Object> args) {
479448 if (arr != null ) {
480449 if (this .CIPHER_KEY .length () > 0 ) {
481450 PubnubCrypto pc = new PubnubCrypto (
482- this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
451+ this .CIPHER_KEY );
483452 arr = pc .decryptJSONArray (arr );
484453 ;
485454 }
@@ -489,7 +458,7 @@ private void _subscribe(HashMap<String, Object> args) {
489458 String msgs = messages .getString (0 );
490459 if (this .CIPHER_KEY .length () > 0 ) {
491460 PubnubCrypto pc = new PubnubCrypto (
492- this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
461+ this .CIPHER_KEY );
493462 msgs = pc .decrypt (msgs );
494463 }
495464 if (callback != null )
@@ -689,7 +658,7 @@ private void _presence(HashMap<String, Object> args) {
689658
690659 if (this .CIPHER_KEY .length () > 0 ) {
691660 // Decrypt Message
692- PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
661+ PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY );
693662 message = pc .decrypt (message );
694663 }
695664 if (callback != null )
@@ -700,7 +669,7 @@ private void _presence(HashMap<String, Object> args) {
700669 if (arr != null ) {
701670 if (this .CIPHER_KEY .length () > 0 ) {
702671 PubnubCrypto pc = new PubnubCrypto (
703- this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
672+ this .CIPHER_KEY );
704673 arr = pc .decryptJSONArray (arr );
705674 }
706675 if (callback != null )
@@ -709,7 +678,7 @@ private void _presence(HashMap<String, Object> args) {
709678 String msgs = messages .getString (0 );
710679 if (this .CIPHER_KEY .length () > 0 ) {
711680 PubnubCrypto pc = new PubnubCrypto (
712- this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
681+ this .CIPHER_KEY );
713682 msgs = pc .decrypt (msgs );
714683 }
715684 if (callback != null )
@@ -748,7 +717,7 @@ public JSONArray here_now(String channel) {
748717
749718 if (this .CIPHER_KEY .length () > 0 ) {
750719 // Decrypt Messages
751- PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
720+ PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY );
752721 return pc .decryptJSONArray (response );
753722 } else {
754723 return response ;
@@ -798,7 +767,7 @@ public JSONArray history(HashMap<String, Object> args) {
798767
799768 if (this .CIPHER_KEY .length () > 0 ) {
800769 // Decrypt Messages
801- PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
770+ PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY );
802771 return pc .decryptJSONArray (response );
803772 } else {
804773 return response ;
@@ -835,7 +804,7 @@ public JSONArray detailedHistory(String channel, long start, long end, int count
835804 JSONArray response = _request (url );
836805
837806 if (this .CIPHER_KEY .length () > 0 ) {
838- PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY , this . INITIALIZATION_VECTOR );
807+ PubnubCrypto pc = new PubnubCrypto (this .CIPHER_KEY );
839808 try {
840809 return pc .decryptJSONArray (response .getJSONArray (0 ));
841810 } catch (JSONException e ) {
@@ -1221,10 +1190,8 @@ class PubnubCrypto {
12211190
12221191 private final String CIPHER_KEY ;
12231192
1224- private final String INITIALIZATION_VECTOR ;
1225- public PubnubCrypto (String CIPHER_KEY , String INITIALIZATION_VECTOR ) {
1193+ public PubnubCrypto (String CIPHER_KEY ) {
12261194 this .CIPHER_KEY = CIPHER_KEY ;
1227- this .INITIALIZATION_VECTOR = INITIALIZATION_VECTOR ;
12281195 }
12291196
12301197 /**
@@ -1369,7 +1336,7 @@ public String decrypt(String cipher_text) throws Exception {
13691336 */
13701337 private byte [] transform (boolean encrypt_or_decrypt , byte [] input_bytes ) throws Exception {
13711338 ByteArrayOutputStream output = new ByteArrayOutputStream ();
1372- byte [] iv_bytes = INITIALIZATION_VECTOR .getBytes ();
1339+ byte [] iv_bytes = "0123456789012345" .getBytes ();
13731340 byte [] key_bytes = md5 (this .CIPHER_KEY );
13741341
13751342 SecretKeySpec key = new SecretKeySpec (key_bytes , "AES" );
0 commit comments