Having an impossible time with encryption


#1

I followed the encryption demo with no problems, but I just cannot seem to load the crypto javascript code into my existing project properly without getting a error when trying to encrypt a simple line of text.

Uncaught TypeError - Cannot read property 'length' of undefined. line 3 column 98

How do I ‘include’ that stanford crypto library so that it works?

Mike


#2

Do you have the library checked in the Libraries window?


#3

No - did not see that - but it still gives me the error after I check it and re-run the app.

Mike


#4

This is the error in the debug console:

StanfordCryptoLibrary.js:2 Uncaught TypeError: Cannot read property 'length' of undefined
    at new sjcl.cipher.aes (StanfordCryptoLibrary.js:2)
    at Object.encrypt (StanfordCryptoLibrary.js:35)
    at HTMLButtonElement.btnRegGo.onclick (code.js:36)
sjcl.cipher.aes @ StanfordCryptoLibrary.js:2
encrypt @ StanfordCryptoLibrary.js:35
btnRegGo.onclick @ code.js:36
hfunc.js:4026 Error encountered:
  Uncaught TypeError: Cannot read property 'length' of undefined 
  Url: http://127.0.0.1:57037/rubidex_sales_system/nsb/library/StanfordCryptoLibrary.js 
  Line: 2 
  Column: 98

I deleted the file and checked the stanford encryption library - and I still get this error.

Mike


#5

This is my code:

txtEncrypted=sjcl.encrypt(txtPassword.value, txtRegFullName.value)
  NSB.MsgBox(txtEncrypted.value)

I also tried:

txtEncrypted.value=sjcl.encrypt(txtPassword.value, txtRegFullName.value)
  NSB.MsgBox(txtEncrypted.value)

I have a string - txtPassword with a defined alpha numeric password - no keywords are in it. I have a string in txtRegFullName - nothing weird in there. All strings are surrounded by double quotes. This is BASIC code.

Mike


#6

I have tried this too. Checking the box does nothing. I was going to drag the js file into project explorer but I never got round to trying it


#7

Anyone else having problems? It works on the example app, but not on my project. I really don’t want to have to start over due to all the form design i’ve completed.

Mike


#8

What framework are you using?


#9

If you mean which controls, common, bootstrap 4 and jqwidgets.

However, I am doing this entirely in code right now.

It’s not working.

Here is the code (just the stuff I am trying to encrypt right now):

Function btnRegGo_onclick()
    Dim txtRegFullName, txtRegAddress, txtRegPhone, txtRegEmail, txtRegUsername, txtRegPassword, txtPlain, txtPassword, webURL, newPublicKey, txtEncrypted

      Rem Put dummy data to test saving and encryption
      txtRegFullName = "Mike Felker"
      txtPassword = "12ghYT43Bscx"

      txtEncrypted = sjcl.encrypt(txtPassword.value, txtRegFullName.value)
      NSB.MsgBox(txtEncrypted.value)

end function

I am getting errors and no message box. I have the library checked and I created a code file in project and copied and pasted the StanfordJavascriptCryptoLibrary in place - followed the directions of the blog post.

Mike


#10

That’s not going to work, for reasons that have nothing to do with sjcl.

You’re being inconsistent with the use of .value. This works:

Dim txtRegFullName, txtRegAddress, txtRegPhone, txtRegEmail, txtRegUsername, txtRegPassword, txtPlain, txtPassword, webURL, newPublicKey, txtEncrypted

  Rem Put dummy data to test saving and encryption
  txtRegFullName = "Mike Felker"
  txtPassword = "12ghYT43Bscx"

  txtEncrypted = sjcl.encrypt(txtPassword, txtRegFullName)
  NSB.MsgBox(txtEncrypted)

#11

Oh for gosh sakes. I was mixing up javascript and BASIC - wasn’t I?

Stupid mistake.

Thanks.

Mike