Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 RC4 Encryption/Decryption

Author  Topic 

saini_balvinder
Starting Member

22 Posts

Posted - 2008-01-03 : 00:19:08
This is related to post :
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=78552

got a issue with this one..im not sure why..

My results are as follows:

Select dbo.fnEncDecRc4('Orange12345', 'Hello123')
Output : ,Mgl
Select dbo.fnEncDecRc4('Orange12345', ',Mgl')
Output : M

i am not able to decrypt it. Any idea why this is hapenning? Does it has to do something with regional settings?

kiruthika
Yak Posting Veteran

67 Posts

Posted - 2008-01-03 : 01:28:33
quote:
Originally posted by saini_balvinder

This is related to post :
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=78552

got a issue with this one..im not sure why..

My results are as follows:

Select dbo.fnEncDecRc4('Orange12345', 'Hello123')
Output : ,Mgl
Select dbo.fnEncDecRc4('Orange12345', ',Mgl')
Output : M

i am not able to decrypt it. Any idea why this is hapenning? Does it has to do something with regional settings?




Hi!
Try this

Select dbo.fnEncDecRc4('Orange12345', 'Hello123') as [Ecryption]

Ecryption
----------
ó,úMÃgl

copy this and paste it to the below function

select dbo.fnEncDecRc4('Orange12345', 'ó,úMÃgl') as [Decryption]

Decryption
-----------
Hello123

It gives the same result

kiruthika!
http://www.ictned.eu



Go to Top of Page

saini_balvinder
Starting Member

22 Posts

Posted - 2008-01-03 : 01:45:17
Hello Kirutika,

Thanks for your reply. i have seen the previous msg for this topic and all of them can encrypt/decrypt successfully. But in my case the query :

Select dbo.fnEncDecRc4('Orange12345', 'Hello123') is giving me this result

,Mgl

Its not the same with your result. Any idea why this is hapenning?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-03 : 01:56:22
Never mind his result. The important thing is that YOU get original text back when decoding the encoded text.
Maybe you are using unicode and kiruthika is not?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

saini_balvinder
Starting Member

22 Posts

Posted - 2008-01-03 : 02:04:48
Hello Peso,

Thanks for that... but thing is im not able to decrypt it... i have following results with different query:

select dbo.fnEncDecRc4('Orange12345',(select dbo.fnEncDecrc4('Orange12345','testing123')))

Result:
!


Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-03 : 02:07:25
Are you using UNICODE collation?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

saini_balvinder
Starting Member

22 Posts

Posted - 2008-01-03 : 02:23:51
Hello Peso,

the application i have is for japan, so when i create a new table by default the unicode is as follows. below is script for my table.

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TBL_FTP]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TBL_FTP]
GO

CREATE TABLE [dbo].[TBL_FTP] (
[Userid] [varchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
[pwd] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[createdate] [smalldatetime] NULL
) ON [PRIMARY]
GO
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-03 : 02:37:23
The columns are still varchar with chinese collation.
Have you tried creating the columns with NVARCHAR instead?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

saini_balvinder
Starting Member

22 Posts

Posted - 2008-01-03 : 02:47:07
Hello peso,

no luck.. i change column type to nvarchar and run the following:

declare @pwd varchar(256)
update tbl_ftp set pwd=dbo.fnEncDecRc4('Orange12345','$Orange1234')
select @pwd=pwd from tbl_ftp
set @pwd=dbo.fnEncDecRc4('Orange12345',@pwd)
print @pwd

Result:
(1 row(s) affected)

!
Go to Top of Page

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2008-01-03 : 14:12:00
quote:
Originally posted by saini_balvinder

Hello peso,

no luck.. i change column type to nvarchar and run the following:

declare @pwd varchar(256)
update tbl_ftp set pwd=dbo.fnEncDecRc4('Orange12345','$Orange1234')
select @pwd=pwd from tbl_ftp
set @pwd=dbo.fnEncDecRc4('Orange12345',@pwd)
print @pwd

Result:
(1 row(s) affected)

!




Common sense would tell you that if you were advised to change your columns to NVarchar, you should also change your variable types to NVarchar as well, wouldn't it?
Go to Top of Page

saini_balvinder
Starting Member

22 Posts

Posted - 2008-01-03 : 21:02:22
tried that too...but same result.

declare @pwd nvarchar(256)
update tbl_ftp set pwd=dbo.fnEncDecRc4('Orange12345','$Orange1234')
select @pwd=pwd from tbl_ftp
set @pwd=dbo.fnEncDecRc4('Orange12345',@pwd)
print @pwd

Result:
!

The problem here is not with datatype or collation i think. because even if use just a "print" statement that also gives me same result.

declare @pwd nvarchar(256)
set @pwd=dbo.fnEncDecRc4('Orange12345','$Orange1234')
print @pwd
set @pwd=dbo.fnEncDecRc4('Orange12345',@pwd)
print @pwd

Result:
@I0n
!
Go to Top of Page
   

- Advertisement -