besoft Active Member Licensed User Longtime User Apr 20, 2016 #1 Greetings I studied example of data encryption. Example function normally. I tried during the encryption and decryption of data to look at how they look. Encryption Code: Copy Dim s As String = "mystring" Dim b() As Byte = Cipher.Encrypt(s.GetBytes("UTF8"), "pwd") Dim test As String = BytesToString(b, 0, b.Length, "UTF8") Log(test) Decryption Code: Copy Dim test_byte() As Byte = test.GetBytes("UTF8") Dim bb() As Byte = Cipher.Decrypt(test_byte, "pwd") Dim ss As String = BytesToString(bb, 0, bb.Length, "UTF8") The problem is presumably in the conversion string back into a byte. I get the following error: Code: Copy org.bouncycastle.crypto.DataLengthException: last block incomplete in decryption Does anyone have any advice on how to convert encrypted string back into a byte? thanks Last edited: Apr 20, 2016
Greetings I studied example of data encryption. Example function normally. I tried during the encryption and decryption of data to look at how they look. Encryption Code: Copy Dim s As String = "mystring" Dim b() As Byte = Cipher.Encrypt(s.GetBytes("UTF8"), "pwd") Dim test As String = BytesToString(b, 0, b.Length, "UTF8") Log(test) Decryption Code: Copy Dim test_byte() As Byte = test.GetBytes("UTF8") Dim bb() As Byte = Cipher.Decrypt(test_byte, "pwd") Dim ss As String = BytesToString(bb, 0, bb.Length, "UTF8") The problem is presumably in the conversion string back into a byte. I get the following error: Code: Copy org.bouncycastle.crypto.DataLengthException: last block incomplete in decryption Does anyone have any advice on how to convert encrypted string back into a byte? thanks
EnriqueGonzalez Expert Licensed User Longtime User Apr 21, 2016 #2 You must use Base 64 (StringUtils) to work with Encryption Code: Copy Dim test As String = BytesToString(b, 0, b.Length, "UTF8") change it to Code: Copy Dim SU As StringUtils Dim test As String = SU.EncodeBase64(b) and this one: Code: Copy Dim test_byte() As Byte = test.GetBytes("UTF8") to: Code: Copy Dim test_byte() As Byte = SU.DecodeBase64(test) I hope it works! Upvote 0
You must use Base 64 (StringUtils) to work with Encryption Code: Copy Dim test As String = BytesToString(b, 0, b.Length, "UTF8") change it to Code: Copy Dim SU As StringUtils Dim test As String = SU.EncodeBase64(b) and this one: Code: Copy Dim test_byte() As Byte = test.GetBytes("UTF8") to: Code: Copy Dim test_byte() As Byte = SU.DecodeBase64(test) I hope it works!
besoft Active Member Licensed User Longtime User Apr 21, 2016 #3 Thank you very much for the solution. Upvote 0