-
Notifications
You must be signed in to change notification settings - Fork 1
/
AES_extension.java
179 lines (141 loc) · 17.6 KB
/
AES_extension.java
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
package com.maresha.aes;
// In The Name Of God
// The most merciful
// Info:
// Developer : (Mohammadreza & Alireza) Sharifi
// License : MIT License
// Spcial Thanks : GFG website and Google :)
// *
// *
// *
// *
// *
// *
// ......... Hope you Enjoy :) .........
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.ComponentCategory;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import java.nio.charset.StandardCharsets;
import java.security.spec.KeySpec;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
@DesignerComponent(
version = 1,
description = "To Encrypt strings with AES",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMj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class MareshaAES extends AndroidNonvisibleComponent implements Component {
public static final int VERSION = 1;
private ComponentContainer container;
private Context context;
private static final String LOG_TAG = "";
public MareshaAES(ComponentContainer container) {
super(container.$form());
this.container = container;
context = (Context) container.$context();
Log.d(LOG_TAG, "Maresha" );
}
@SimpleFunction(description = "Encrypt arbitrary string via AES")
public String AESEncrypt(String text,String salt,String secret){
return AES.encrypt(text,salt, secret);
}
@SimpleFunction(description = "Decrypt arbitrary string via AES")
public String AESDecrypt(String text,String salt,String secret){
return AES.decrypt(text,salt, secret);
}
@SimpleFunction(description = "Generate SALT")
public String Salt(String secret){
return AES.encrypt("Default text hust in case ","Non default salt forexample",secret);
}
public static final class AES {
// Encrypt method
public static String encrypt(String strToEncrypt,final String SALT,final String SECRET_KEY)
{
try {
// Create default byte array
byte[] iv = { 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 };
IvParameterSpec ivspec
= new IvParameterSpec(iv);
// Create SecretKeyFactory object
SecretKeyFactory factory
= SecretKeyFactory.getInstance(
"PBKDF2WithHmacSHA256");
// Create KeySpec object and assign with
// constructor
KeySpec spec = new PBEKeySpec(
SECRET_KEY.toCharArray(), SALT.getBytes(),
65536, 256);
SecretKey tmp = factory.generateSecret(spec);
SecretKeySpec secretKey = new SecretKeySpec(
tmp.getEncoded(), "AES");
Cipher cipher = Cipher.getInstance(
"AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey,
ivspec);
// Return encrypted string
return Base64.getEncoder().encodeToString(
cipher.doFinal(strToEncrypt.getBytes(
StandardCharsets.UTF_8)));
}
catch (Exception e) {
System.out.println("Error while encrypting: "
+ e.toString());
}
return "Error";
}
// This method use to decrypt to string
public static String decrypt(String strToDecrypt,final String SALT,final String SECRET_KEY)
{
try {
// Default byte array
byte[] iv = { 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 };
// Create IvParameterSpec object and assign with
// constructor
IvParameterSpec ivspec
= new IvParameterSpec(iv);
// Create SecretKeyFactory Object
SecretKeyFactory factory
= SecretKeyFactory.getInstance(
"PBKDF2WithHmacSHA256");
// Create KeySpec object and assign with
// constructor
KeySpec spec = new PBEKeySpec(
SECRET_KEY.toCharArray(), SALT.getBytes(),
65536, 256);
SecretKey tmp = factory.generateSecret(spec);
SecretKeySpec secretKey = new SecretKeySpec(
tmp.getEncoded(), "AES");
Cipher cipher = Cipher.getInstance(
"AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey,
ivspec);
// Return decrypted string
return new String(cipher.doFinal(
Base64.getDecoder().decode(strToDecrypt)));
}
catch (Exception e) {
System.out.println("Error while decrypting: "
+ e.toString());
}
return "Error";
}
}
}
// Thanks