Error in encrypting json data with openssl plugin

You’ll also leak less memory.

Hello and thanks ,

I use top code and run the project. Error is in this line:

local tmp = cipher:encrypt( tmp )

Thank you

Where are you getting this feature?   cipher.*

I am not familiar with it.  Do you have a link to it in the docs? 

Or, is this code you got from another site?

PS - Same question for mime.*

I’m looking at the openSSL examples and this isn’t quite the same.

https://github.com/coronalabs/plugins-sample-openssl

https://github.com/coronalabs/plugins-sample-openssl/blob/master/Encryption/main.lua

Here are some tests from the source lib repository too:

https://github.com/zhaozg/lua-openssl/tree/master/test

This procedure works fine as I use it for all my saved json.

@Ed, cipher is part of openSSL plugin

Ensure you follow all the steps as outlined here - https://coronalabs.com/blog/2013/06/11/tutorial-using-the-openssl-plugin/

You are probably missing a constructor for cipher

local cipher = openssl.get\_cipher ( "aes-256-cbc" )

Hello ,

I wrote the code from here. But did not work.

I define the cipher at the top of the module; Before of all the functions.

mime.* is a standard library in the LuaSockets library which we include with our builds. This gives us socket.*, http.* etc. 

Rob

Cool.  I’m afraid this shows a boundary of my knowledge and experience.

@roaminggammer, it’s a pretty well *hidden feature*. I doubt many people know about it.

Rob

Break your code down into steps so you can find the code/line that fails.  

Then, dig into the possible causes of failure on that line.

Doing all the work on one line makes it difficult to debug.

That error message tells me that the one of these is returning something bad that hoses up the sequence:

  • mime.b64
  • cipher:encrypt
  • json.encode

or that your data is bad

  • M.data

I would personally re-write it as this to find the point of failure:

print("------------ 1\n") print(m ~= nil, "m exists") print("------------ 2\n") for k,v in pairs(m.data) do print(k,v, "data in m") end print("------------ 3\n") local tmp = print(json.encode(M.data)) print(tmp) print("------------ 4\n") local tmp = cipher:encrypt( tmp ) print(tmp) print("------------ 5\n") local tmp = mime.b64( tmp ) print(tmp) -- By the time you get here, You'll know which line part of the code failed.

You’ll also leak less memory.

Hello and thanks ,

I use top code and run the project. Error is in this line:

local tmp = cipher:encrypt( tmp )

Thank you

Where are you getting this feature?   cipher.*

I am not familiar with it.  Do you have a link to it in the docs? 

Or, is this code you got from another site?

PS - Same question for mime.*

I’m looking at the openSSL examples and this isn’t quite the same.

https://github.com/coronalabs/plugins-sample-openssl

https://github.com/coronalabs/plugins-sample-openssl/blob/master/Encryption/main.lua

Here are some tests from the source lib repository too:

https://github.com/zhaozg/lua-openssl/tree/master/test

This procedure works fine as I use it for all my saved json.

@Ed, cipher is part of openSSL plugin

Ensure you follow all the steps as outlined here - https://coronalabs.com/blog/2013/06/11/tutorial-using-the-openssl-plugin/

You are probably missing a constructor for cipher

local cipher = openssl.get\_cipher ( "aes-256-cbc" )

Hello ,

I wrote the code from here. But did not work.

I define the cipher at the top of the module; Before of all the functions.

mime.* is a standard library in the LuaSockets library which we include with our builds. This gives us socket.*, http.* etc. 

Rob

Cool.  I’m afraid this shows a boundary of my knowledge and experience.

@roaminggammer, it’s a pretty well *hidden feature*. I doubt many people know about it.

Rob