11-29-2005 1:59 PM
Hi All,
I need to encrypt a field which is <u><b>50 characters</b></u> in length and also decrypt the same.
Please let me know if there is <u><b>any Function Modules or Class Methods</b></u> to achieve the requirement.
Thanks in advance.
Regards
Nanda
11-29-2005 2:03 PM
Nanda,
See the Function Modules:
K_ENCRYPT_RESOURCE
K_DECRYPT_RESOURCE
See the Class : CL_HTTP_UTILITY
It has got two methods for ur requirement
Thanks
Kam
Message was edited by: Kam
11-29-2005 2:05 PM
These will only do it for a length of 32
report zrich_0002.
parameters: p_pass type FIEB_ENCRYPTED_PASSWD..
data: encrypted type FIEB_ENCRYPTED_PASSWD.
data: decrypted type FIEB_ENCRYPTED_PASSWD.
call function 'FIEB_PASSWORD_ENCRYPT'
exporting
im_decrypted_password = p_pass
importing
ex_encrypted_password = encrypted.
call function 'FIEB_PASSWORD_DECRYPT'
exporting
im_encrypted_password = encrypted
importing
ex_decrypted_password = decrypted.
write:/ p_pass.
write:/ encrypted.
write:/ decrypted.
Regards,
Rich Heilman
11-29-2005 2:10 PM
Rich,
Is the Decryption works in this?????
I am seeing only spaces for decrypted variable!!!!
Thanks
Kam
11-29-2005 2:18 PM
This code works very well in my system. I have heard that it does not work so well in other systems.
In this sample program, I have copied out all of the code which was in the function modules of the previous sample program. Here I have made a couple changes that allow you to have a 50 character field. You could just copy the function group/function modules into "Z" versions and make the changes there, then just use the "Z" functions.
[code]
report zrich_0001.
constants:
This are the characters that are allowed for the decrypted password
co_password_characters(94) type c value
' !"#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQ' &
'RSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
number of passwrod characters
co_number_of_characters type i value 94,
max length of the encrypted and of the decrypted password
co_password_length type i value <b>50</b> " Make a change here, make it 50,
This is the key
co_key<b>(50) " Make a change here, make it 50</b> type c value
'Wz=M?LrU&N\`E!@mBb K/n)e;SvR+Da['.
parameters: p_pass(50) type c .
data: encrypted(50) type c .
data: decrypted(50) type c .
perform encrypt_password
using
p_pass
changing
encrypted.
perform decrypt_password
using
encrypted
changing
decrypted.
write:/ p_pass.
write:/ encrypted.
write:/ decrypted.
----
FORM ENCRYPT_PASSWORD *
----
........ *
----
--> IM_DECRYPTED_PASSWORD *
--> CH_ENCRYPTED_PASSWORD *
----
form encrypt_password using im_decrypted_password
changing ch_encrypted_password.
We use a simple 'Vigenere-Chiffre' (but with a long key) and
add a accumulated index to it.
By now the encrypted and the decrypted password have the same
length (32)
data:
l_index type i,
l_number type i,
l_key_val type i,
l_passwd_val type i,
l_accumulate type i.
clear ch_encrypted_password.
l_index = 0.
l_accumulate = 0.
encrypt the maximal length of the decrypted password, not just the
filled part of the decrypted password
do co_password_length times.
check out the index in the key
perform character_search
using
co_password_characters
co_key+l_index(1)
changing
l_key_val.
check out the index in the decrypted password
perform character_search
using
co_password_characters
im_decrypted_password+l_index(1)
changing
l_passwd_val.
calculate the index of the character for the encrypted password
l_number = ( l_accumulate + l_key_val + l_passwd_val ) mod
co_number_of_characters.
ch_encrypted_password+l_index(1) =
co_password_characters+l_number(1).
l_index = l_index + 1.
Accumulate the index of the characters in the decrypted password
l_accumulate = l_accumulate + l_passwd_val.
enddo.
endform. " ENCRYPT_PASSWORD
----
FORM DECRYPT_PASSWORD *
----
........ *
----
--> IM_ENCRYPTED_PASSWORD *
--> CH_DECRYPTED_PASSWORD *
----
form decrypt_password using im_encrypted_password
changing ch_decrypted_password.
We use a simple 'Vigenere-Chiffre' (but with a long key) and
add a accumulated index to it.
By now the encrypted and the decrypted password have the same
length (32)
data:
l_index type i,
l_number type i,
l_key_val type i,
l_passwd_val type i,
l_accumulate type i.
clear ch_decrypted_password.
l_index = 0.
l_accumulate = 0.
encrypt the maximal length of the decrypted password, not just the
filled part of the decrypted password
do co_password_length times.
check out the index in the key
perform character_search
using
co_password_characters
co_key+l_index(1)
changing
l_key_val.
check out the index in the encrypted password
perform character_search
using
co_password_characters
im_encrypted_password+l_index(1)
changing
l_passwd_val.
calculate the index of the character for the encrypted password
l_number = ( l_passwd_val - l_accumulate - l_key_val ) mod
co_number_of_characters.
ch_decrypted_password+l_index(1) =
co_password_characters+l_number(1).
l_index = l_index + 1.
Accumulate the index of the characters in the decrypted password
l_accumulate = l_accumulate + l_number.
enddo.
endform. " DECRYPT_PASSWORD
----
FORM character_search *
----
........ *
----
--> IM_STRING *
--> IM_CHARACTER *
--> CH_POS *
----
form character_search using im_string
im_character
changing ch_pos type i.
data:
l_index type i,
l_length type i.
describe field im_string length l_length.
ch_pos = -1.
l_index = 0.
do l_length times.
if im_string+l_index(1) = im_character.
ch_pos = l_index.
exit.
endif.
l_index = l_index + 1.
enddo.
endform. " character_search
[/code]
Again, this may not even work in your system. It works in mine.
Regards,
Rich Heilman
11-29-2005 2:09 PM
Hi Nanda,
You can use the following classes for Encryption/Decription.
CL_HARD_WIRED_ENCRYPTOR and CL_RSDMD_CRYPT
Regards,
Raj
11-29-2005 2:16 PM
Hi Nanda,
See these two methods of class CL_HARD_WIRED_ENCRYPTOR
ENCRYPT_BYTES2BYTES - Gets Hard-Wired Encryption of Xstring
DECRYPT_BYTES2BYTES - Gets Hard-Wired Decryption of Xstring
Hope it is useful.
Regards,
Raj
11-29-2005 2:25 PM
Hi Rich,
Thanks for the response, but my requirement is for a field of 50 chars.I dont think it will be possible by FIEB_PASSWORD_ENCRYPT and FIEB_PASSWORD_DECRYPT as it will do only for the 32 characters.
Regards
Nanda
11-29-2005 2:26 PM
02-14-2006 10:42 PM
Compilation error with
In Unicode, DESCRIBE LENGTH can only be used with the IN BYTE MODE or
IN CHARACTER MODE addition.
describe field im_string length l_length
How do I get the length?
02-15-2006 4:55 AM
Hi Nanda,
here is one simple way of encrypt and decrypt.
I m Using an Interface if_http_utility of class cl_http_utility.
*************************************************
data: z type string,
encode type string,
decode type string .
data: obj type ref to CL_http_utility,
cref type ref to if_http_utility.
create object : obj.
cref = obj.
z = 'what u have to encode'.
encode = obj->if_HTTP_UTILITY~enCODE_BASE64( z ) .
decode = obj->if_HTTP_UTILITY~enCODE_BASE64( encode ).
****************************************************
Regards
-
Sachin Dhingra
11-22-2006 9:43 AM
BASE64 is not encryption and class CL_HARD_WIRED_ENCRYPTOR is not very secure. Make sure you are comfortable with the very week encryption it provides. The option that Rich provides in this thread is much better.
regards,
Nigel