| @ -0,0 +1,141 @@ | |||
| package com.nivesh.production.bajajfd.util | |||
| import android.annotation.SuppressLint | |||
| import android.util.Base64 | |||
| import android.util.Log | |||
| import com.nivesh.production.bajajfd.util.Constants.Companion.passphrase | |||
| import java.security.InvalidAlgorithmParameterException | |||
| import java.security.InvalidKeyException | |||
| import java.security.MessageDigest | |||
| import java.security.NoSuchAlgorithmException | |||
| import java.text.SimpleDateFormat | |||
| import java.util.* | |||
| import javax.crypto.* | |||
| import javax.crypto.spec.IvParameterSpec | |||
| import javax.crypto.spec.SecretKeySpec | |||
| class EncryptionDecryption { | |||
| val TAG = "Crypto" | |||
| private var aesCipher: Cipher? = null | |||
| private var secretKey: SecretKey? = null | |||
| private var ivParameterSpec: IvParameterSpec? = null | |||
| private val CIPHER_TRANSFORMATION = "AES/CBC/PKCS5Padding" | |||
| private val CIPHER_ALGORITHM = "AES" | |||
| // Replace me with a 16-byte key, share between Java and C# | |||
| private val rawSecretKey = byteArrayOf( | |||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |||
| ) | |||
| private val MESSAGEDIGEST_ALGORITHM = "MD5" | |||
| @SuppressLint("NotConstructor") | |||
| fun EncryptionDecryption() { | |||
| val passwordKey = | |||
| encodeDigest(passphrase) //new NativeClass().localName(KeyConstant.passphrase)); | |||
| try { | |||
| aesCipher = Cipher.getInstance(CIPHER_TRANSFORMATION) | |||
| } catch (e: NoSuchAlgorithmException) { | |||
| Log.e(TAG, "No such algorithm $CIPHER_ALGORITHM", e) | |||
| } catch (e: NoSuchPaddingException) { | |||
| Log.e(TAG, "No such padding PKCS5", e) | |||
| } | |||
| secretKey = SecretKeySpec(passwordKey, CIPHER_ALGORITHM) | |||
| ivParameterSpec = IvParameterSpec(rawSecretKey) | |||
| } | |||
| fun encryptAsBase64(dataToEncrypt: String): String? { | |||
| var dataToEncrypt = dataToEncrypt | |||
| val dateFormat = SimpleDateFormat("SSS", Locale.US) | |||
| dataToEncrypt = dataToEncrypt + dateFormat.format(Date()) | |||
| val encryptedData = encrypt(dataToEncrypt.toByteArray()) | |||
| return Base64.encodeToString(encryptedData, Base64.DEFAULT) | |||
| } | |||
| // public String decrypt(String textToDecrypt) throws Exception { | |||
| // | |||
| // | |||
| // //SecretKeySpec skeySpec = new SecretKeySpec(getRaw(plainText, AESSalt), "AES"); | |||
| // //Cipher cipher = Cipher.getInstance(cypherInstance); | |||
| // //cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(initializationVector.getBytes())); | |||
| // byte[] decrypted = aesCipher.doFinal(encryted_bytes); | |||
| // return new String(decrypted, "UTF-8"); | |||
| // } | |||
| // public String decrypt(String textToDecrypt) throws Exception { | |||
| // | |||
| // | |||
| // //SecretKeySpec skeySpec = new SecretKeySpec(getRaw(plainText, AESSalt), "AES"); | |||
| // //Cipher cipher = Cipher.getInstance(cypherInstance); | |||
| // //cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(initializationVector.getBytes())); | |||
| // byte[] decrypted = aesCipher.doFinal(encryted_bytes); | |||
| // return new String(decrypted, "UTF-8"); | |||
| // } | |||
| fun decrypt(encryptString: String?): String? { | |||
| var decryptedData = "" | |||
| try { | |||
| aesCipher!!.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec) | |||
| } catch (e: InvalidKeyException) { | |||
| Log.e(TAG, "Invalid key", e) | |||
| return null | |||
| } catch (e: InvalidAlgorithmParameterException) { | |||
| Log.e(TAG, "Invalid algorithm $CIPHER_ALGORITHM", e) | |||
| return null | |||
| } | |||
| val decryptBytes: ByteArray | |||
| try { | |||
| val encryted_bytes = Base64.decode(encryptString, Base64.DEFAULT) | |||
| decryptBytes = aesCipher!!.doFinal(encryted_bytes) | |||
| decryptedData = String(decryptBytes) | |||
| decryptedData = decryptedData.substring(0, decryptedData.length - 3) | |||
| } catch (e: IllegalBlockSizeException) { | |||
| Log.e(TAG, "Illegal block size", e) | |||
| return null | |||
| } catch (e: BadPaddingException) { | |||
| Log.e(TAG, "Bad padding", e) | |||
| return null | |||
| } catch (e: Exception) { | |||
| e.printStackTrace() | |||
| } | |||
| return decryptedData | |||
| } | |||
| fun encrypt(clearData: ByteArray?): ByteArray? { | |||
| try { | |||
| aesCipher!!.init(Cipher.ENCRYPT_MODE, secretKey, ivParameterSpec) | |||
| } catch (e: InvalidKeyException) { | |||
| Log.e(TAG, "Invalid key", e) | |||
| return null | |||
| } catch (e: InvalidAlgorithmParameterException) { | |||
| Log.e(TAG, "Invalid algorithm $CIPHER_ALGORITHM", e) | |||
| return null | |||
| } | |||
| val encryptedData: ByteArray | |||
| encryptedData = try { | |||
| aesCipher!!.doFinal(clearData) | |||
| } catch (e: IllegalBlockSizeException) { | |||
| Log.e(TAG, "Illegal block size", e) | |||
| return null | |||
| } catch (e: BadPaddingException) { | |||
| Log.e(TAG, "Bad padding", e) | |||
| return null | |||
| } | |||
| return encryptedData | |||
| } | |||
| private fun encodeDigest(text: String): ByteArray? { | |||
| val digest: MessageDigest | |||
| try { | |||
| digest = MessageDigest.getInstance(MESSAGEDIGEST_ALGORITHM) | |||
| return digest.digest(text.toByteArray()) | |||
| } catch (e: NoSuchAlgorithmException) { | |||
| Log.e(TAG, "No such algorithm $MESSAGEDIGEST_ALGORITHM", e) | |||
| } | |||
| return null | |||
| } | |||
| } | |||
| @ -0,0 +1,50 @@ | |||
| package com.nivesh.production.bajajfd.util | |||
| import android.annotation.SuppressLint | |||
| import android.app.AlertDialog | |||
| import android.content.Context | |||
| import android.graphics.Color | |||
| import android.graphics.drawable.ColorDrawable | |||
| import android.util.Log | |||
| import android.view.Window | |||
| import android.widget.ProgressBar | |||
| @SuppressLint("StaticFieldLeak") | |||
| object ProgressUtil{ | |||
| private lateinit var dialogBuilder: AlertDialog.Builder | |||
| private lateinit var alertDialog: AlertDialog | |||
| private lateinit var pDialog: ProgressBar | |||
| fun showLoading(ctx: Context){ | |||
| // instantiating the lateint objects | |||
| dialogBuilder= AlertDialog.Builder(ctx) | |||
| pDialog= ProgressBar(ctx) | |||
| // setting up the dialog | |||
| dialogBuilder.setCancelable(false) | |||
| dialogBuilder.setView(pDialog) | |||
| alertDialog=dialogBuilder.create() | |||
| // magic of transparent background goes here | |||
| alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); | |||
| // setting the alertDialog's BackgroundDrawable as the color resource of any color with 1% opacity | |||
| alertDialog.window?.setBackgroundDrawable(ColorDrawable(Color.parseColor("#00141414"))) | |||
| // finally displaying the Alertdialog containging the ProgressBar | |||
| alertDialog.show() | |||
| } | |||
| fun hideLoading(){ | |||
| try { | |||
| if(alertDialog.isShowing){ | |||
| alertDialog.dismiss() | |||
| } | |||
| } catch (e: UninitializedPropertyAccessException) { | |||
| Log.e("TAG","AlertDialog UninitializedPropertyAccessException") | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,65 @@ | |||
| package com.nivesh.production.bajajfd.util | |||
| import android.content.Context | |||
| import androidx.preference.PreferenceManager | |||
| class SharedPrefrenceDataMethods { | |||
| companion object { | |||
| fun getLoginEmail(Name: String?, context: Context?): String? { | |||
| val preferences = context?.let { | |||
| PreferenceManager.getDefaultSharedPreferences( | |||
| it | |||
| ) | |||
| } | |||
| return preferences?.getString(Name, "") | |||
| } | |||
| fun getLoginUserCode(Name: String?, context: Context?): String? { | |||
| val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } | |||
| return preferences?.getString(Name, "") | |||
| } | |||
| fun setLogin_SOCIALID(json: String?, context: Context?, Name: String?) { | |||
| val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } | |||
| val editor = preferences?.edit() | |||
| editor?.putString(Name, json) | |||
| editor?.apply() | |||
| } | |||
| fun getLoginSOCIALID(Name: String?, context: Context?): String? { | |||
| val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } | |||
| return preferences?.getString(Name, "") | |||
| } | |||
| fun getLoginPassword(Name: String?, context: Context?): String? { | |||
| val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } | |||
| return preferences?.getString(Name, "") | |||
| } | |||
| fun getLogin_Type(Name: String?, context: Context?): String? { | |||
| val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } | |||
| return preferences?.getString(Name, "") | |||
| } | |||
| fun getVersionCode(Name: String?, context: Context?): String? { | |||
| val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } | |||
| return preferences?.getString(Name, "") | |||
| } | |||
| fun getGcmAppId(Name: String?, context: Context?): String? { | |||
| val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } | |||
| return preferences?.getString(Name, "") | |||
| } | |||
| fun setToken(context: Context?, token: String?) { | |||
| val preferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } | |||
| val editor = preferences?.edit() | |||
| editor?.putString("token", token) | |||
| editor?.apply() | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,169 @@ | |||
| package com.nivesh.production.bajajfd.util | |||
| import android.Manifest | |||
| import android.annotation.SuppressLint | |||
| import android.content.Context | |||
| import android.content.pm.PackageManager | |||
| import android.os.Build | |||
| import android.provider.Settings | |||
| import android.telephony.TelephonyManager | |||
| import android.text.TextUtils | |||
| import android.util.Log | |||
| import androidx.core.app.ActivityCompat | |||
| import com.nivesh.production.bajajfd.model.DeviceInfo | |||
| import java.nio.charset.StandardCharsets | |||
| import java.security.MessageDigest | |||
| import java.util.* | |||
| class Utility { | |||
| companion object{ | |||
| fun convert_sha256(rawString: String): String { | |||
| return try { | |||
| val digest = MessageDigest.getInstance("SHA-256") | |||
| var hash = ByteArray(0) | |||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | |||
| hash = digest.digest(rawString.toByteArray(StandardCharsets.UTF_8)) | |||
| } | |||
| val hexString = StringBuilder() | |||
| for (i in hash.indices) { | |||
| val hex = Integer.toHexString(0xff and hash[i].toInt()) | |||
| if (hex.length == 1) hexString.append('0') | |||
| hexString.append(hex) | |||
| } | |||
| hexString.toString().uppercase(Locale.getDefault()) | |||
| } catch (ex: Exception) { | |||
| throw RuntimeException(ex) | |||
| } | |||
| } | |||
| fun convert_sha256_2X(rawString: String): String { | |||
| return try { | |||
| val digest = MessageDigest.getInstance("SHA-256") | |||
| var hash = ByteArray(0) | |||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | |||
| hash = digest.digest(rawString.toByteArray(StandardCharsets.UTF_8)) | |||
| } | |||
| val hexString = java.lang.StringBuilder() | |||
| for (i in hash.indices) { | |||
| val hex = Integer.toHexString(0xff and hash[i].toInt()) | |||
| if (hex.length == 1) hexString.append('0') | |||
| hexString.append(hex) | |||
| } | |||
| hexString.toString() | |||
| } catch (ex: java.lang.Exception) { | |||
| throw java.lang.RuntimeException(ex) | |||
| } | |||
| } | |||
| @SuppressLint("HardwareIds") | |||
| fun getDeviceInfo(mContext: Context): DeviceInfo { | |||
| val deviceInfo = DeviceInfo() | |||
| var device_id: String? = "" | |||
| try { | |||
| val telephonyManager = | |||
| mContext.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager | |||
| deviceInfo.app_version = ( | |||
| SharedPrefrenceDataMethods.getVersionCode( | |||
| Constants.KEY_VERSION_CODE, | |||
| mContext | |||
| ) | |||
| ) | |||
| deviceInfo.device_model = (if (TextUtils.isEmpty(Build.DEVICE)) "" else Build.DEVICE) | |||
| deviceInfo.device_os_version = (if (TextUtils.isEmpty(Build.VERSION.RELEASE)) "" else Build.VERSION.RELEASE) | |||
| deviceInfo.device_name = (if (TextUtils.isEmpty(Build.PRODUCT)) "" else Build.PRODUCT) | |||
| deviceInfo.device_token = ( | |||
| if (TextUtils.isEmpty( | |||
| SharedPrefrenceDataMethods.getGcmAppId( | |||
| Constants.KEY_GCM_APP_ID, | |||
| mContext | |||
| ) | |||
| ) | |||
| ) "" else SharedPrefrenceDataMethods.getGcmAppId( | |||
| Constants.KEY_GCM_APP_ID, | |||
| mContext | |||
| ) | |||
| ) | |||
| deviceInfo.device_type = ("Android") | |||
| // Hemant Code Added start 28-10-2020 | |||
| if (ActivityCompat.checkSelfPermission( | |||
| mContext, | |||
| Manifest.permission.READ_PHONE_STATE | |||
| ) != PackageManager.PERMISSION_GRANTED | |||
| ) { | |||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |||
| device_id = telephonyManager.imei | |||
| if (device_id == null) { | |||
| device_id = | |||
| if (TextUtils.isEmpty(Build.getSerial())) "" else Build.getSerial() | |||
| } | |||
| } else { | |||
| device_id = telephonyManager.deviceId | |||
| if (device_id == null) { | |||
| device_id = | |||
| if (TextUtils.isEmpty(Build.SERIAL)) "" else Build.SERIAL | |||
| } | |||
| } | |||
| } else { | |||
| device_id = telephonyManager.deviceId | |||
| if (device_id == null) { | |||
| device_id = if (TextUtils.isEmpty(Build.SERIAL)) "" else Build.SERIAL | |||
| } | |||
| } | |||
| if (device_id == null || device_id.isEmpty() || device_id.equals( | |||
| "unknown", | |||
| ignoreCase = true | |||
| ) | |||
| ) { | |||
| device_id = if (TextUtils.isEmpty( | |||
| Settings.Secure.getString( | |||
| mContext.contentResolver, | |||
| Settings.Secure.ANDROID_ID | |||
| ) | |||
| ) | |||
| ) "" else Settings.Secure.getString( | |||
| mContext.contentResolver, | |||
| Settings.Secure.ANDROID_ID | |||
| ) | |||
| } | |||
| Log.e("device_id", "-> $device_id") | |||
| // Hemant changes 07-11-2019 start commented and Added 12-12-2019 | |||
| // deviceInfo.device_id = (device_id + "#" + com.nivesh.production.util.Utility.getFlavor()) | |||
| // Hemant changes 07-11-2019 end commented and Added 12-12-2019 | |||
| // Hemant changes 07-11-2019 start added and commented 12-12-2019 | |||
| deviceInfo.device_id_for_UMSId = (device_id) | |||
| // deviceInfo.setDeviceId(device_id); | |||
| // Hemant changes 07-11-2019 end added and commented 12-12-2019 | |||
| } catch (e: java.lang.Exception) { | |||
| e.printStackTrace() | |||
| // Hemant changes 07-11-2019 start Added 28-10-2020 | |||
| if (device_id == null || device_id.isEmpty() || device_id.equals( | |||
| "unknown", | |||
| ignoreCase = true | |||
| ) | |||
| ) { | |||
| device_id = if (TextUtils.isEmpty( | |||
| Settings.Secure.getString( | |||
| mContext.contentResolver, | |||
| Settings.Secure.ANDROID_ID | |||
| ) | |||
| ) | |||
| ) "" else Settings.Secure.getString( | |||
| mContext.contentResolver, | |||
| Settings.Secure.ANDROID_ID | |||
| ) | |||
| } | |||
| Log.e("device_id", "-> $device_id") | |||
| // deviceInfo.setDeviceId(device_id + "#" + com.nivesh.production.util.Utility.getFlavor()) | |||
| deviceInfo.device_id_for_UMSId = (device_id) | |||
| // Hemant changes 07-11-2019 end Added 28-10-2020 | |||
| } | |||
| return deviceInfo | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,21 @@ | |||
| package com.nivesh.production.bajajfd.util | |||
| import android.annotation.SuppressLint | |||
| import java.text.SimpleDateFormat | |||
| import java.util.* | |||
| class Utils_Functions { | |||
| companion object{ | |||
| fun getCurrentDateStamp(): String? { | |||
| val d = Date() | |||
| @SuppressLint("SimpleDateFormat") val simpleDateFormat = | |||
| SimpleDateFormat("yyyy-MM-dd HH:mm:ss") | |||
| val dateStr = simpleDateFormat.format(d) | |||
| val output = d.time / 1000L | |||
| val str = java.lang.Long.toString(output) | |||
| return d.time.toString() | |||
| } | |||
| } | |||
| } | |||
Powered by TurnKey Linux.