PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > SQL Server 2005 Data encryption problem
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
SQL Server 2005 Data encryption problem

Réponse
 
LinkBack Outils de la discussion
Vieux 08/09/2008, 00h09   #1
Ajit
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut SQL Server 2005 Data encryption problem

Hi,

We are using SQL Server 2005 Express edition.We encrypt data in the table
using asymmetric keys:

CREATE ASYMMETRIC KEY MyKey AUTHORIZATION dbo With ALGORITHM = RSA_512
ENCRYPTION BY PASSWORD = 'wcixoOEb5h77gh5'

This was run aginst the master database.To our surprise, what we found is
that SQL Server won't accepts any key names starting with nonalphabetic
characters. We do the encryption as follows :

INSERT INTO CardInfo (OrderId, PAN, ExpDate, CardType, LastCardDigits)
VALUES('10004',
CONVERT(varbinary(300),EncryptByAsymKey(AsymKey_ID ('MyKey'),'1001100110011001')),
CONVERT(varbinary(150),EncryptByAsymKey(AsymKey_ID ('MyKey'),'1210')),
CONVERT(varbinary(100),EncryptByAsymKey(AsymKey_ID ('MyKey'),'VI')),
'1001')

Now we try to decrypt the data using the key name and password.

SELECT CONVERT(nvarchar(300),DecryptByAsymKey(AsymKey_ID( 'MyKey'), PAN,
N'wcixoOEb5h77gh5')),
CONVERT(nvarchar(150),DecryptByAsymKey(AsymKey_ID( 'MyKey'), ExpDate,
N'wcixoOEb5h77gh5')),
CONVERT(nvarchar(100),DecryptByAsymKey(AsymKey_ID( 'MyKey'), CardType,
N'wcixoOEb5h77gh5'))
FROM CardInfo WHERE OrderId = '10004'

But its returning some junk data only.What could be the problem ?
We have SQL Server sp2 also installed. AsymKey_ID('MyKey') returns a valid
integer.

Is there any way to trace this problem ?


With Regards
Ajit
  Réponse avec citation
Vieux 08/09/2008, 08h27   #2
John Bell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SQL Server 2005 Data encryption problem


"Ajit" <Ajit@discussions.microsoft.com> wrote in message
news:40F33B84-7E80-48F9-AD62-303101B553B1@microsoft.com...
> Hi,
>
> We are using SQL Server 2005 Express edition.We encrypt data in the table
> using asymmetric keys:
>
> CREATE ASYMMETRIC KEY MyKey AUTHORIZATION dbo With ALGORITHM = RSA_512
> ENCRYPTION BY PASSWORD = 'wcixoOEb5h77gh5'
>
> This was run aginst the master database.To our surprise, what we found is
> that SQL Server won't accepts any key names starting with nonalphabetic
> characters. We do the encryption as follows :
>
> INSERT INTO CardInfo (OrderId, PAN, ExpDate, CardType, LastCardDigits)
> VALUES('10004',
> CONVERT(varbinary(300),EncryptByAsymKey(AsymKey_ID ('MyKey'),'1001100110011001')),
> CONVERT(varbinary(150),EncryptByAsymKey(AsymKey_ID ('MyKey'),'1210')),
> CONVERT(varbinary(100),EncryptByAsymKey(AsymKey_ID ('MyKey'),'VI')),
> '1001')
>
> Now we try to decrypt the data using the key name and password.
>
> SELECT CONVERT(nvarchar(300),DecryptByAsymKey(AsymKey_ID( 'MyKey'), PAN,
> N'wcixoOEb5h77gh5')),
> CONVERT(nvarchar(150),DecryptByAsymKey(AsymKey_ID( 'MyKey'), ExpDate,
> N'wcixoOEb5h77gh5')),
> CONVERT(nvarchar(100),DecryptByAsymKey(AsymKey_ID( 'MyKey'), CardType,
> N'wcixoOEb5h77gh5'))
> FROM CardInfo WHERE OrderId = '10004'
>
> But its returning some junk data only.What could be the problem ?
> We have SQL Server sp2 also installed. AsymKey_ID('MyKey') returns a valid
> integer.
>
> Is there any way to trace this problem ?
>
>
> With Regards
> Ajit


Hi

The problem seems to be the conversion to/from nvarchar because your have
not inserted nvarchar.

either decrypt with:
SELECT CONVERT(varchar(300),DecryptByAsymKey(AsymKey_ID(' MyKey'), PAN,
N'wcixoOEb5h77gh5')),
CONVERT(varchar(150),DecryptByAsymKey(AsymKey_ID(' MyKey'), ExpDate,
N'wcixoOEb5h77gh5')),
CONVERT(varchar(100),DecryptByAsymKey(AsymKey_ID(' MyKey'), CardType,
N'wcixoOEb5h77gh5'))
FROM CardInfo WHERE OrderId = '10004'

or encrypt with:
INSERT INTO CardInfo (OrderId, PAN, ExpDate, CardType, LastCardDigits)
VALUES('10005',
CONVERT(varbinary(300),EncryptByAsymKey(AsymKey_ID ('MyKey'),N'1001100110011001')),
CONVERT(varbinary(150),EncryptByAsymKey(AsymKey_ID ('MyKey'),N'1210')),
CONVERT(varbinary(100),EncryptByAsymKey(AsymKey_ID ('MyKey'),N'VI')),
'1001')


SELECT CONVERT(nvarchar(300),DecryptByAsymKey(AsymKey_ID( 'MyKey'), PAN,
N'wcixoOEb5h77gh5')),
CONVERT(nvarchar(150),DecryptByAsymKey(AsymKey_ID( 'MyKey'), ExpDate,
N'wcixoOEb5h77gh5')),
CONVERT(nvarchar(100),DecryptByAsymKey(AsymKey_ID( 'MyKey'), CardType,
N'wcixoOEb5h77gh5'))
FROM CardInfo WHERE OrderId = '10005'

John

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h01.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08734 seconds with 10 queries