cancel
Showing results for 
Search instead for 
Did you mean: 

How to encrypt and decrypt?

Former Member
0 Kudos

Hi, experts,

I need to encrypt a string and decrypt the encrypted string .

Action:

1. create three input fields(password_input, encrypted_input, decrypted_input) and two button (encrypted_button and decrypted_button) in the view of the WDA.

2. run the application.

3. When type the password in the password_input, clicking the encrypted_button, the encrypted data is put in the encrypted_input.

4. When click the decrypted_button, the encrypted data is decrypted and put it to the decrypted_input.

I don't know how to complete the 3 and 4 step. I need some code or example for coding the encrypting and decrypting.

Thanks a lot.

Best regards,

Tao

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, Wang,

I don´t know in which version you are, but you can check if there is the class (SE24) CL_HARD_WIRED_ENCRYPTOR, and try it.

Hope this helps!

Andre

Former Member
0 Kudos

Hi, Andre,

Thanks a lot for your help in advance.

The version of my R3 system is that basis is 14, and abap is 14.

I can find the class CL_HARD_WIRED_ENCRYPTOR, and find the CLASS_CONSTRUCTOR method to create a object that type is CL_HARD_WIRED_ENCRYPTOR. I modify my code of the method ONACTIONSETENCRYPTED. The following is my code:

method ONACTIONSETENCRYPTED .

DATA lo_nd_node TYPE REF TO if_wd_context_node.

DATA lo_el_node TYPE REF TO if_wd_context_element.

DATA if_encrypt TYPE REF TO CL_HARD_WIRED_ENCRYPTOR.

DATA ls_node TYPE wd_this->element_node.

DATA lv_password LIKE ls_node-password.

DATA lv_encrypted_password LIKE ls_node-encrypted_password.

DATA lv_decrypted_password LIKE ls_node-decrypted_password.

  • navigate from <CONTEXT> to <NODE> via lead selection

lo_nd_node = wd_context->get_child_node( name = wd_this->wdctx_node ).

  • get element via lead selection

lo_el_node = lo_nd_node->get_element( ).

  • get single attribute

lo_el_node->get_attribute(

EXPORTING

name = `PASSWORD`

IMPORTING

value = lv_password ).

  • create a CL_HARD_WIRED_ENCRYPTOR

if_encrypt = CL_HARD_WIRED_ENCRYPTOR=>CLASS_CONSTRUCTOR( ).

  • ENCRYPTOR the string

lv_encrypted_password = if_encrypt=>ENCRYPT_STRING2STRING( THE_STRING = lv_password ).

  • DECRYPTOR the string

lv_decrypted_password = if_encrypt=>DECRYPT_STRING2STRING( THE_STRING = lv_encrypted_password ).

endmethod.

But when I compiled my code, the system occured a error: You cannot call the special method "CLASS_CONSTRUCTOR(" directly.

I don't know how to solve the problem, and how to create the object of CL_HARD_WIRED_ENCRYPTOR type for encrypting and decrypting. I need some code or example for coding the CL_HARD_WIRED_ENCRYPTOR class.

Do you give me some hints? Thanks a lot.

Thanks a billion.

Best regards,

Tao

Former Member
0 Kudos

Hi, Andre,

Thanks a lot for your help in advance.

Now, I have sloved the problem .

Thanks a billion.

Best regards,

Tao

Former Member
0 Kudos

hai ,

I am facing the same problem.can you tell me how to slove that problem.

"You cannot call the special method "CLASS_CONSTRUCTOR(" directly. "

Regards,

Arun

Former Member
0 Kudos

Hi,

Try this way, it will solve your problem....you can not call constructor of the class directly....

*this code is under the encrypt button

DATA if_encrypt TYPE REF TO cl_hard_wired_encryptor.

CREATE OBJECT if_encrypt.

  • ENCRYPTOR the string

TRY.

CALL METHOD if_encrypt->encrypt_string2string

EXPORTING

the_string = lv_string_value <-this is a string coming from user-i mean user input this value from the screen

receiving

RESULT = lv_encypt_value <----this one i declared as string as well...

.

CATCH cx_encrypt_error .

ENDTRY.

*for decryption--- put this code under your decrypt button

*since they are two different action methods that is why i needed to create the instance again.

DATA if_encrypt TYPE REF TO cl_hard_wired_encryptor.

CREATE OBJECT if_encrypt.

TRY.

CALL METHOD if_encrypt->decrypt_string2string

EXPORTING

the_string = lv_encypt_value <---declared as string, as above

receiving

RESULT = lv_decrypt_value <---declared as string as well

.

CATCH cx_encrypt_error .

ENDTRY.

thanks

AS.

Answers (1)

Answers (1)

Former Member
0 Kudos

hi tao!

How to troubleshoot the error ?????

"You cannot call the special method "CLASS_CONSTRUCTOR(" directly. "

reference:

eh tried but nothing.... and I have the same code that you.

Best regards,

RHD.