How Write same function of sql in c# [Resolved]

Posted by Cpatil1000 under C# on 3/29/2016 | Points: 10 | Views : 2344 | Status : [Member] | Replies : 2
Hi,
How Write same function of sql in c#. Now our software audit has been started. so I want same sql function convert into c#. So when user send username and password to check exist or not. that time password must be send by Encrypt.

CREATE FUNCTION [dbo].[ufn_EncryptString] ( @pClearString VARCHAR(100) )
RETURNS NVARCHAR(100) WITH ENCRYPTION AS
BEGIN

DECLARE @vEncryptedString NVARCHAR(100)
DECLARE @vIdx INT
DECLARE @vBaseIncrement INT

SET @vIdx = 1
SET @vBaseIncrement = 128
SET @vEncryptedString = ''

WHILE @vIdx <= LEN(@pClearString)
BEGIN
SET @vEncryptedString = @vEncryptedString +
NCHAR(ASCII(SUBSTRING(@pClearString, @vIdx, 1)) +
@vBaseIncrement + @vIdx - 1)
SET @vIdx = @vIdx + 1
END

RETURN @vEncryptedString

END
GO




Responses

Posted by: Rajnilari2015 on: 3/29/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Try this

/*
CREATE FUNCTION [dbo].[ufn_EncryptString] ( @pClearString VARCHAR(100) )
RETURNS NVARCHAR(100) WITH ENCRYPTION AS
BEGIN
*/

function ufn_EncryptString string (pClearString string)
{

/*
DECLARE @vEncryptedString NVARCHAR(100)
DECLARE @vIdx INT
DECLARE @vBaseIncrement INT

SET @vIdx = 1
SET @vBaseIncrement = 128
SET @vEncryptedString = ''
*/

string vEncryptedString = string.Empty;
int vIdx = 1;
int vBaseIncrement = 128;

/*
WHILE @vIdx <= LEN(@pClearString)
BEGIN
SET @vEncryptedString = @vEncryptedString +
NCHAR(ASCII(SUBSTRING(@pClearString, @vIdx, 1)) +
@vBaseIncrement + @vIdx - 1)
SET @vIdx = @vIdx + 1
END
*/

while(vIdx <= pClearString.length){

vEncryptedString = vEncryptedString + Char.ConvertFromUtf32(pClearString.Substring(vIdx,1) + vBaseIncrement + vIdx - 1);
vIdx = vIdx + 1;

}

/*
RETURN @vEncryptedString
*/

return vEncryptedString;
}


--
Thanks & Regards,
RNA Team

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 3/29/2016 [Member] Silver | Points: 25

Up
0
Down
The above query will work. Nice query written by Rajni.


Feel free to share informations.
mail Id ' adityagupta200@gmail.com
Thanks

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response