Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim anno, mese, giorno, chiave As String
anno = "2017"
mese = "03"
giorno = "05"
chiave = "123456"
Dim verificaanno(), verificamese(), verificagiorno() As Byte
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim cifro As B4XCipher
Dim encode, decode As StringUtils
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim annocrypt(), mesecrypt(), giornocrypt() As Byte
Dim a_crypt, m_crypt, g_crypt As String
annocrypt = Encrypt(anno)
a_crypt = encode.EncodeBase64(annocrypt)
Log(a_crypt)
mesecrypt = Encrypt(mese)
m_crypt = encode.EncodeBase64(mesecrypt)
Log(m_crypt)
giornocrypt = Encrypt(giorno)
g_crypt = encode.EncodeBase64(giornocrypt)
Log(g_crypt)
Dim map3 As Map
map3.Initialize
If File.Exists(File.DirInternal,"licenza.ini") Then
map3 = File.ReadMap(File.DirInternal, "licenza.ini")
Log("Anno: " & map3.Get("anno"))
verificaanno = decode.DecodeBase64(map3.Get("anno"))
verificamese = decode.DecodeBase64(map3.Get("mese"))
verificagiorno = decode.DecodeBase64(map3.Get("giorno"))
Dim a_decrypt, m_decrypt, g_decrypt As String
a_decrypt = Decrypt(verificaanno)
m_decrypt = Decrypt(verificamese)
g_decrypt = Decrypt(verificagiorno)
Else
Dim map2 As Map
map2.Initialize
map2.Put("anno", a_crypt )
map2.Put("mese", m_crypt )
map2.Put("giorno", g_crypt )
File.WriteMap(File.DirInternal, "licenza.ini", map2)
verificaanno = decode.DecodeBase64(a_crypt)
verificamese = decode.DecodeBase64(m_crypt)
verificagiorno = decode.DecodeBase64(g_crypt)
Dim a_decrypt, m_decrypt, g_decrypt As String
a_decrypt = Decrypt(verificaanno)
m_decrypt = Decrypt(verificamese)
g_decrypt = Decrypt(verificagiorno)
End If
Dim targetDate As Long = DateUtils.SetDate(a_decrypt, m_decrypt, g_decrypt)' uso 3 caselle di testo per l'anno, mese, giorno che memorizzano i dati in un db.
Dim timeToDate As Period = DateUtils.PeriodBetween(DateTime.Now, targetDate)
Msgbox("Time left to 2017: " & timeToDate.Months & " months, " & timeToDate.Days & " days","")
If timeToDate.Months = 0 And timeToDate.Days = 0 Then ' se risultano a 0 allora mi da licenza scaduta altrimenti continua ad utilizzarlo
Msgbox("Licenza scaduta","")
Else
Msgbox("vai tranquillo","")
End If
End Sub
Sub Encrypt(testo As String) As Byte()
Dim ByteArray() As Byte
ByteArray=cifro.Encrypt(testo.GetBytes("UTF8"), chiave)
Return ByteArray
End Sub
Sub Decrypt(testo() As Byte) As String
Dim ByteArray() As Byte
ByteArray=cifro.Decrypt(testo, chiave)
Return BytesToString(ByteArray, 0, ByteArray.Length, "UTF8")
End Sub