igpf Member Licensed User Longtime User Sep 30, 2018 #1 hi, not sure where to post this question. but i'm trying to "AES/CBC/PKCS7Padding" signature with 16 bit block, it has to be specific, i've been looking at all the forums, but just don't seem to make it happen. obviously, i'm new to encryption methods, not to b4a. i'm trying to connect to a python server that's using specific encryption... the app is using tcp, to send its encoded AES256, then compressed, then padded pkcs7? if that doesn't make any sense i'm sorry, i'm using the python code to try and mimic the connection... can someone point me in the right direction please?
hi, not sure where to post this question. but i'm trying to "AES/CBC/PKCS7Padding" signature with 16 bit block, it has to be specific, i've been looking at all the forums, but just don't seem to make it happen. obviously, i'm new to encryption methods, not to b4a. i'm trying to connect to a python server that's using specific encryption... the app is using tcp, to send its encoded AES256, then compressed, then padded pkcs7? if that doesn't make any sense i'm sorry, i'm using the python code to try and mimic the connection... can someone point me in the right direction please?
Erel B4X founder Staff member Licensed User Longtime User Sep 30, 2018 #2 Where is the code? Upvote 0
KMatle Expert Licensed User Longtime User Sep 30, 2018 #3 See this lib: https://www.b4x.com/android/forum/threads/base64-and-encryption-library.6839/#content I use it for RSA and other stuff. Give it a try if PKCS7Padding is supported (I guess no as it uses the Java standards) Code: c.Initialize("AES/CBC/PKCS5Padding") There's a discussion here: https://stackoverflow.com/questions/29232705/encrypt-text-to-aes-cbc-pkcs7padding saying that PKCS5 is the same but PKCS7 uses another blocksize. Upvote 0
See this lib: https://www.b4x.com/android/forum/threads/base64-and-encryption-library.6839/#content I use it for RSA and other stuff. Give it a try if PKCS7Padding is supported (I guess no as it uses the Java standards) Code: c.Initialize("AES/CBC/PKCS5Padding") There's a discussion here: https://stackoverflow.com/questions/29232705/encrypt-text-to-aes-cbc-pkcs7padding saying that PKCS5 is the same but PKCS7 uses another blocksize.
igpf Member Licensed User Longtime User Oct 1, 2018 #4 @Erel -- sorry, i'll post the code shortly @KMatle Code: c.Initialize("AES/CBC/PKCS5Padding") This is where I was leading to.. how do you know if I can try Code: c.Initialize("AES/CBC/PKCS7Padding") ? I'm using the encryption v1.1 library. For my understanding PKCS5Padding only allow 8bit key block, while PKCS7Padding allows 255bit... I needed to match other code that uses a 16bit key block... So is there an update for the encryption library? or is there a work-around for the key block size issue.. sorry, i'll post code up shortly... -igpf Upvote 0
@Erel -- sorry, i'll post the code shortly @KMatle Code: c.Initialize("AES/CBC/PKCS5Padding") This is where I was leading to.. how do you know if I can try Code: c.Initialize("AES/CBC/PKCS7Padding") ? I'm using the encryption v1.1 library. For my understanding PKCS5Padding only allow 8bit key block, while PKCS7Padding allows 255bit... I needed to match other code that uses a 16bit key block... So is there an update for the encryption library? or is there a work-around for the key block size issue.. sorry, i'll post code up shortly... -igpf
Jeffrey Cameron Well-Known Member Licensed User Longtime User Oct 1, 2018 #5 The concept is the same as the following thread, perhaps it may help: https://www.b4x.com/android/forum/threads/encrypt-on-android-decrypt-on-net.93318/#post-590878 Upvote 0
The concept is the same as the following thread, perhaps it may help: https://www.b4x.com/android/forum/threads/encrypt-on-android-decrypt-on-net.93318/#post-590878
igpf Member Licensed User Longtime User Oct 2, 2018 #6 Code: Public Sub Encode(sCMD As String) As Byte() Dim c As Cipher Dim kg As KeyGenerator Dim bData() As Byte Dim sCypherKey as String c.Initialize("AES/CBC/PKCS7Padding") sCypherKey = "12345asdf##$#$" kg.Initialize("AES") kg.KeyFromBytes(sCypherKey.GetBytes("utf8")) bData = c.Encrypt(sCMD.GetBytes("utf8"), kg.Key, False) Return bData End Sub there it is... when i get to c.encrypt(cmd...) i get ... any thoughts??? Last edited: Oct 2, 2018 Upvote 0
Code: Public Sub Encode(sCMD As String) As Byte() Dim c As Cipher Dim kg As KeyGenerator Dim bData() As Byte Dim sCypherKey as String c.Initialize("AES/CBC/PKCS7Padding") sCypherKey = "12345asdf##$#$" kg.Initialize("AES") kg.KeyFromBytes(sCypherKey.GetBytes("utf8")) bData = c.Encrypt(sCMD.GetBytes("utf8"), kg.Key, False) Return bData End Sub there it is... when i get to c.encrypt(cmd...) i get ... any thoughts???
Erel B4X founder Staff member Licensed User Longtime User Oct 2, 2018 #7 igpf said: any thoughts??? Click to expand... You should post error messages as text. The key should be 16 bytes long: Code: sCypherKey = "12345asdf##$#$" Dim cc() As Byte = sCypherKey.GetBytes("UTF8") Dim keyinput(16) As Byte Bit.ArrayCopy(cc, 0, keyinput, 0, cc.Length) kg.Initialize("AES") kg.KeyFromBytes(keyinput) Upvote 0
igpf said: any thoughts??? Click to expand... You should post error messages as text. The key should be 16 bytes long: Code: sCypherKey = "12345asdf##$#$" Dim cc() As Byte = sCypherKey.GetBytes("UTF8") Dim keyinput(16) As Byte Bit.ArrayCopy(cc, 0, keyinput, 0, cc.Length) kg.Initialize("AES") kg.KeyFromBytes(keyinput)
igpf Member Licensed User Longtime User Oct 5, 2018 #8 Erel said: You should post error messages as text. The key should be 16 bytes long: Code: sCypherKey = "12345asdf##$#$" Dim cc() As Byte = sCypherKey.GetBytes("UTF8") Dim keyinput(16) As Byte Bit.ArrayCopy(cc, 0, keyinput, 0, cc.Length) kg.Initialize("AES") kg.KeyFromBytes(keyinput) Click to expand... just wanted to update, this does work. but i had found my answer. Code: Dim passHash() As Byte Dim md As MessageDigest passHash = md.GetMessageDigest(sCypherKey.GetBytes("utf8"),"MD5") kg.KeyFromBytes(passHash) thanks for all the help. Upvote 0
Erel said: You should post error messages as text. The key should be 16 bytes long: Code: sCypherKey = "12345asdf##$#$" Dim cc() As Byte = sCypherKey.GetBytes("UTF8") Dim keyinput(16) As Byte Bit.ArrayCopy(cc, 0, keyinput, 0, cc.Length) kg.Initialize("AES") kg.KeyFromBytes(keyinput) Click to expand... just wanted to update, this does work. but i had found my answer. Code: Dim passHash() As Byte Dim md As MessageDigest passHash = md.GetMessageDigest(sCypherKey.GetBytes("utf8"),"MD5") kg.KeyFromBytes(passHash) thanks for all the help.