BRRSA.smali
16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
.class public Lcom/brplug/encrypt/BRRSA;
.super Ljava/lang/Object;
.source "BRRSA.java"
# static fields
.field private static final KEY_ALGORITHM:Ljava/lang/String; = "RSA"
.field private static final KEY_LENGTH:I = 0x400
# instance fields
.field private mKey:Ljava/lang/String;
# direct methods
.method public constructor <init>(Ljava/lang/String;)V
.locals 0
.line 33
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 34
iput-object p1, p0, Lcom/brplug/encrypt/BRRSA;->mKey:Ljava/lang/String;
return-void
.end method
.method public static generatorKey()[Ljava/lang/String;
.locals 4
const/4 v0, 0x2
.line 43
:try_start_0
new-array v0, v0, [Ljava/lang/String;
const-string v1, "RSA"
.line 45
invoke-static {v1}, Ljava/security/KeyPairGenerator;->getInstance(Ljava/lang/String;)Ljava/security/KeyPairGenerator;
move-result-object v1
const/16 v2, 0x400
.line 46
invoke-virtual {v1, v2}, Ljava/security/KeyPairGenerator;->initialize(I)V
.line 47
invoke-virtual {v1}, Ljava/security/KeyPairGenerator;->generateKeyPair()Ljava/security/KeyPair;
move-result-object v1
.line 48
invoke-virtual {v1}, Ljava/security/KeyPair;->getPublic()Ljava/security/PublicKey;
move-result-object v2
check-cast v2, Ljava/security/interfaces/RSAPublicKey;
.line 49
invoke-virtual {v1}, Ljava/security/KeyPair;->getPrivate()Ljava/security/PrivateKey;
move-result-object v1
check-cast v1, Ljava/security/interfaces/RSAPrivateKey;
const/4 v3, 0x0
.line 51
invoke-static {v2}, Lcom/brplug/encrypt/BRRSA;->getPublicKey(Ljava/security/PublicKey;)Ljava/lang/String;
move-result-object v2
aput-object v2, v0, v3
const/4 v2, 0x1
.line 52
invoke-static {v1}, Lcom/brplug/encrypt/BRRSA;->getPrivateKey(Ljava/security/PrivateKey;)Ljava/lang/String;
move-result-object v1
aput-object v1, v0, v2
:try_end_0
.catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0
return-object v0
:catch_0
move-exception v0
.line 56
invoke-virtual {v0}, Ljava/lang/Throwable;->printStackTrace()V
const-string v0, ""
.line 59
filled-new-array {v0, v0}, [Ljava/lang/String;
move-result-object v0
return-object v0
.end method
.method private static getPrivateKey(Ljava/security/PrivateKey;)Ljava/lang/String;
.locals 0
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
.line 63
invoke-interface {p0}, Ljava/security/PrivateKey;->getEncoded()[B
move-result-object p0
invoke-static {p0}, Lcom/brplug/encrypt/BRBase64;->encode([B)Ljava/lang/String;
move-result-object p0
return-object p0
.end method
.method private static getPublicKey(Ljava/security/PublicKey;)Ljava/lang/String;
.locals 0
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
.line 67
invoke-interface {p0}, Ljava/security/PublicKey;->getEncoded()[B
move-result-object p0
invoke-static {p0}, Lcom/brplug/encrypt/BRBase64;->encode([B)Ljava/lang/String;
move-result-object p0
return-object p0
.end method
.method private outputDecrypt(Ljavax/crypto/Cipher;Ljava/lang/String;)[B
.locals 6
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
.line 92
invoke-static {p2}, Lcom/brplug/encrypt/BRBase64;->decode(Ljava/lang/String;)[B
move-result-object p2
.line 93
array-length v0, p2
.line 96
new-instance v1, Ljava/io/ByteArrayOutputStream;
invoke-direct {v1}, Ljava/io/ByteArrayOutputStream;-><init>()V
const/4 v2, 0x0
move v3, v2
:goto_0
sub-int v4, v0, v2
if-lez v4, :cond_1
const/16 v5, 0x80
if-le v4, v5, :cond_0
.line 100
invoke-virtual {p1, p2, v2, v5}, Ljavax/crypto/Cipher;->doFinal([BII)[B
move-result-object v2
goto :goto_1
.line 102
:cond_0
invoke-virtual {p1, p2, v2, v4}, Ljavax/crypto/Cipher;->doFinal([BII)[B
move-result-object v2
.line 104
:goto_1
invoke-virtual {v1, v2}, Ljava/io/ByteArrayOutputStream;->write([B)V
add-int/lit8 v3, v3, 0x1
mul-int/lit16 v2, v3, 0x80
goto :goto_0
.line 108
:cond_1
invoke-virtual {v1}, Ljava/io/ByteArrayOutputStream;->close()V
.line 109
invoke-virtual {v1}, Ljava/io/ByteArrayOutputStream;->toByteArray()[B
move-result-object p1
return-object p1
.end method
.method private outputEncrypt(Ljavax/crypto/Cipher;Ljava/lang/String;)[B
.locals 6
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
.line 71
invoke-virtual {p2}, Ljava/lang/String;->getBytes()[B
move-result-object p2
.line 72
array-length v0, p2
.line 75
new-instance v1, Ljava/io/ByteArrayOutputStream;
invoke-direct {v1}, Ljava/io/ByteArrayOutputStream;-><init>()V
const/4 v2, 0x0
move v3, v2
:goto_0
sub-int v4, v0, v2
if-lez v4, :cond_1
const/16 v5, 0x75
if-le v4, v5, :cond_0
.line 79
invoke-virtual {p1, p2, v2, v5}, Ljavax/crypto/Cipher;->doFinal([BII)[B
move-result-object v2
goto :goto_1
.line 81
:cond_0
invoke-virtual {p1, p2, v2, v4}, Ljavax/crypto/Cipher;->doFinal([BII)[B
move-result-object v2
.line 83
:goto_1
invoke-virtual {v1, v2}, Ljava/io/ByteArrayOutputStream;->write([B)V
add-int/lit8 v3, v3, 0x1
mul-int/lit8 v2, v3, 0x75
goto :goto_0
.line 87
:cond_1
invoke-virtual {v1}, Ljava/io/ByteArrayOutputStream;->close()V
.line 88
invoke-virtual {v1}, Ljava/io/ByteArrayOutputStream;->toByteArray()[B
move-result-object p1
return-object p1
.end method
# virtual methods
.method public decryptByPrivate(Ljava/lang/String;)Ljava/lang/String;
.locals 3
.line 141
:try_start_0
iget-object v0, p0, Lcom/brplug/encrypt/BRRSA;->mKey:Ljava/lang/String;
invoke-static {v0}, Lcom/brplug/encrypt/BRBase64;->decode(Ljava/lang/String;)[B
move-result-object v0
.line 142
new-instance v1, Ljava/security/spec/PKCS8EncodedKeySpec;
invoke-direct {v1, v0}, Ljava/security/spec/PKCS8EncodedKeySpec;-><init>([B)V
const-string v0, "RSA"
.line 143
invoke-static {v0}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;
move-result-object v0
.line 144
invoke-virtual {v0, v1}, Ljava/security/KeyFactory;->generatePrivate(Ljava/security/spec/KeySpec;)Ljava/security/PrivateKey;
move-result-object v0
check-cast v0, Ljava/security/interfaces/RSAPrivateKey;
const-string v1, "RSA/ECB/PKCS1Padding"
.line 145
invoke-static {v1}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;
move-result-object v1
const/4 v2, 0x2
.line 146
invoke-virtual {v1, v2, v0}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;)V
.line 147
new-instance v0, Ljava/lang/String;
invoke-direct {p0, v1, p1}, Lcom/brplug/encrypt/BRRSA;->outputDecrypt(Ljavax/crypto/Cipher;Ljava/lang/String;)[B
move-result-object p1
invoke-direct {v0, p1}, Ljava/lang/String;-><init>([B)V
:try_end_0
.catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0
return-object v0
:catch_0
move-exception p1
.line 149
invoke-virtual {p1}, Ljava/lang/Throwable;->printStackTrace()V
const-string p1, ""
return-object p1
.end method
.method public decryptByPublic(Ljava/lang/String;)Ljava/lang/String;
.locals 3
.line 181
:try_start_0
iget-object v0, p0, Lcom/brplug/encrypt/BRRSA;->mKey:Ljava/lang/String;
invoke-static {v0}, Lcom/brplug/encrypt/BRBase64;->decode(Ljava/lang/String;)[B
move-result-object v0
.line 182
new-instance v1, Ljava/security/spec/X509EncodedKeySpec;
invoke-direct {v1, v0}, Ljava/security/spec/X509EncodedKeySpec;-><init>([B)V
const-string v0, "RSA"
.line 183
invoke-static {v0}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;
move-result-object v0
.line 184
invoke-virtual {v0, v1}, Ljava/security/KeyFactory;->generatePublic(Ljava/security/spec/KeySpec;)Ljava/security/PublicKey;
move-result-object v0
check-cast v0, Ljava/security/interfaces/RSAPublicKey;
const-string v1, "RSA/ECB/PKCS1Padding"
.line 185
invoke-static {v1}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;
move-result-object v1
const/4 v2, 0x2
.line 186
invoke-virtual {v1, v2, v0}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;)V
.line 187
new-instance v0, Ljava/lang/String;
invoke-direct {p0, v1, p1}, Lcom/brplug/encrypt/BRRSA;->outputDecrypt(Ljavax/crypto/Cipher;Ljava/lang/String;)[B
move-result-object p1
invoke-direct {v0, p1}, Ljava/lang/String;-><init>([B)V
:try_end_0
.catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0
return-object v0
:catch_0
move-exception p1
.line 189
invoke-virtual {p1}, Ljava/lang/Throwable;->printStackTrace()V
const-string p1, ""
return-object p1
.end method
.method public encryptByPrivate(Ljava/lang/String;)Ljava/lang/String;
.locals 4
.line 118
iget-object v0, p0, Lcom/brplug/encrypt/BRRSA;->mKey:Ljava/lang/String;
invoke-static {v0}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z
move-result v0
const-string v1, ""
if-nez v0, :cond_1
invoke-static {p1}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z
move-result v0
if-eqz v0, :cond_0
goto :goto_0
.line 121
:cond_0
:try_start_0
iget-object v0, p0, Lcom/brplug/encrypt/BRRSA;->mKey:Ljava/lang/String;
invoke-static {v0}, Lcom/brplug/encrypt/BRBase64;->decode(Ljava/lang/String;)[B
move-result-object v0
.line 122
new-instance v2, Ljava/security/spec/PKCS8EncodedKeySpec;
invoke-direct {v2, v0}, Ljava/security/spec/PKCS8EncodedKeySpec;-><init>([B)V
const-string v0, "RSA"
.line 123
invoke-static {v0}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;
move-result-object v0
.line 124
invoke-virtual {v0, v2}, Ljava/security/KeyFactory;->generatePrivate(Ljava/security/spec/KeySpec;)Ljava/security/PrivateKey;
move-result-object v0
check-cast v0, Ljava/security/interfaces/RSAPrivateKey;
const-string v2, "RSA/ECB/PKCS1Padding"
.line 125
invoke-static {v2}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;
move-result-object v2
const/4 v3, 0x1
.line 126
invoke-virtual {v2, v3, v0}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;)V
.line 127
invoke-direct {p0, v2, p1}, Lcom/brplug/encrypt/BRRSA;->outputEncrypt(Ljavax/crypto/Cipher;Ljava/lang/String;)[B
move-result-object p1
invoke-static {p1}, Lcom/brplug/encrypt/BRBase64;->encode([B)Ljava/lang/String;
move-result-object p1
:try_end_0
.catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0
return-object p1
:catch_0
move-exception p1
.line 129
invoke-virtual {p1}, Ljava/lang/Throwable;->printStackTrace()V
:cond_1
:goto_0
return-object v1
.end method
.method public encryptByPublic(Ljava/lang/String;)Ljava/lang/String;
.locals 3
.line 161
:try_start_0
iget-object v0, p0, Lcom/brplug/encrypt/BRRSA;->mKey:Ljava/lang/String;
invoke-static {v0}, Lcom/brplug/encrypt/BRBase64;->decode(Ljava/lang/String;)[B
move-result-object v0
.line 162
new-instance v1, Ljava/security/spec/X509EncodedKeySpec;
invoke-direct {v1, v0}, Ljava/security/spec/X509EncodedKeySpec;-><init>([B)V
const-string v0, "RSA"
.line 163
invoke-static {v0}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;
move-result-object v0
.line 164
invoke-virtual {v0, v1}, Ljava/security/KeyFactory;->generatePublic(Ljava/security/spec/KeySpec;)Ljava/security/PublicKey;
move-result-object v0
check-cast v0, Ljava/security/interfaces/RSAPublicKey;
const-string v1, "RSA/ECB/PKCS1Padding"
.line 165
invoke-static {v1}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;
move-result-object v1
const/4 v2, 0x1
.line 166
invoke-virtual {v1, v2, v0}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;)V
.line 167
invoke-direct {p0, v1, p1}, Lcom/brplug/encrypt/BRRSA;->outputEncrypt(Ljavax/crypto/Cipher;Ljava/lang/String;)[B
move-result-object p1
invoke-static {p1}, Lcom/brplug/encrypt/BRBase64;->encode([B)Ljava/lang/String;
move-result-object p1
:try_end_0
.catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0
return-object p1
:catch_0
move-exception p1
.line 169
invoke-virtual {p1}, Ljava/lang/Throwable;->printStackTrace()V
const-string p1, ""
return-object p1
.end method
.method public privateSign(Ljava/lang/String;)Ljava/lang/String;
.locals 3
:try_start_0
const-string v0, "SHA1withRSA"
.line 201
invoke-static {v0}, Ljava/security/Signature;->getInstance(Ljava/lang/String;)Ljava/security/Signature;
move-result-object v0
.line 202
iget-object v1, p0, Lcom/brplug/encrypt/BRRSA;->mKey:Ljava/lang/String;
invoke-static {v1}, Lcom/brplug/encrypt/BRBase64;->decode(Ljava/lang/String;)[B
move-result-object v1
.line 204
new-instance v2, Ljava/security/spec/PKCS8EncodedKeySpec;
invoke-direct {v2, v1}, Ljava/security/spec/PKCS8EncodedKeySpec;-><init>([B)V
const-string v1, "RSA"
.line 205
invoke-static {v1}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;
move-result-object v1
.line 207
invoke-virtual {v1, v2}, Ljava/security/KeyFactory;->generatePrivate(Ljava/security/spec/KeySpec;)Ljava/security/PrivateKey;
move-result-object v1
check-cast v1, Ljava/security/interfaces/RSAPrivateKey;
.line 208
invoke-virtual {v0, v1}, Ljava/security/Signature;->initSign(Ljava/security/PrivateKey;)V
.line 209
invoke-virtual {p1}, Ljava/lang/String;->getBytes()[B
move-result-object p1
invoke-virtual {v0, p1}, Ljava/security/Signature;->update([B)V
.line 211
invoke-virtual {v0}, Ljava/security/Signature;->sign()[B
move-result-object p1
invoke-static {p1}, Lcom/brplug/encrypt/BRBase64;->encode([B)Ljava/lang/String;
move-result-object p1
:try_end_0
.catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0
return-object p1
:catch_0
move-exception p1
.line 213
invoke-virtual {p1}, Ljava/lang/Throwable;->printStackTrace()V
const-string p1, ""
return-object p1
.end method
.method public publicVerify(Ljava/lang/String;Ljava/lang/String;)Z
.locals 3
:try_start_0
const-string v0, "SHA1withRSA"
.line 226
invoke-static {v0}, Ljava/security/Signature;->getInstance(Ljava/lang/String;)Ljava/security/Signature;
move-result-object v0
.line 227
iget-object v1, p0, Lcom/brplug/encrypt/BRRSA;->mKey:Ljava/lang/String;
invoke-static {v1}, Lcom/brplug/encrypt/BRBase64;->decode(Ljava/lang/String;)[B
move-result-object v1
.line 229
new-instance v2, Ljava/security/spec/X509EncodedKeySpec;
invoke-direct {v2, v1}, Ljava/security/spec/X509EncodedKeySpec;-><init>([B)V
const-string v1, "RSA"
.line 230
invoke-static {v1}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;
move-result-object v1
.line 232
invoke-virtual {v1, v2}, Ljava/security/KeyFactory;->generatePublic(Ljava/security/spec/KeySpec;)Ljava/security/PublicKey;
move-result-object v1
check-cast v1, Ljava/security/interfaces/RSAPublicKey;
.line 233
invoke-virtual {v0, v1}, Ljava/security/Signature;->initVerify(Ljava/security/PublicKey;)V
.line 234
invoke-virtual {p2}, Ljava/lang/String;->getBytes()[B
move-result-object p2
invoke-virtual {v0, p2}, Ljava/security/Signature;->update([B)V
.line 236
invoke-static {p1}, Lcom/brplug/encrypt/BRBase64;->decode(Ljava/lang/String;)[B
move-result-object p1
invoke-virtual {v0, p1}, Ljava/security/Signature;->verify([B)Z
move-result p1
:try_end_0
.catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0
return p1
:catch_0
move-exception p1
.line 238
invoke-virtual {p1}, Ljava/lang/Throwable;->printStackTrace()V
const/4 p1, 0x0
return p1
.end method