Kredi kartı bilgieri nasıl şifrelenmiş olarka veritabanına kaydedilir(MS SQL)
kaynak: http://www.cihanozhan.com/sql-server-ile-veri-sifreleme-data-encryption/
CREATE LOGIN BankingDBLogin WITH Password = '1976';
GO
CREATE USER BankingDBUser FOR LOGIN BankingDBLogin;
go
CREATE TABLE Accounts
(
AccountID INT,
FName NVARCHAR(25),
LName NVARCHAR(25),
CreditCardType VARBINARY(1000),
CreditCardNumber VARBINARY(1000),
AccountNotes VARBINARY(MAX)
);
GO
GRANT SELECT, INSERT ON Accounts TO BankingDBUser;
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '1976';
CREATE ASYMMETRIC KEY BankingDBUserAsymmetricKey AUTHORIZATION BankingDBUser
WITH ALGORITHM = RSA_2048 ENCRYPTION BY PASSWORD = '1976';
CREATE SYMMETRIC KEY BankingDBUserSymmetricKey WITH ALGORITHM = AES_256
ENCRYPTION BY ASYMMETRIC KEY BankingDBUserAsymmetricKey;
CREATE SEQUENCE [dbo].[AccountSeq] AS INT
START WITH 1
INCREMENT BY 1
GO
OPEN SYMMETRIC KEY BankingDBUserSymmetricKey DECRYPTION BY ASYMMETRIC KEY BankingDBUserAsymmetricKey WITH PASSWORD = '1976' --AsymmetricKey oluşturuyoruz şifre
INSERT INTO Accounts VALUES(NEXT VALUE FOR dbo.AccountSeq, 'Vedat','Pala',
EncryptByKey(Key_GUID('BankingDBUserSymmetricKey'),'MasterCard'),
EncryptByKey(Key_GUID('BankingDBUserSymmetricKey'),'8961-4152-6325-9852'),
EncryptByKey(Key_GUID('BankingDBUserSymmetricKey'),'Bilgileri gizledik.'));
CLOSE SYMMETRIC KEY BankingDBUserSymmetricKey
SELECT * FROM Accounts;
OPEN SYMMETRIC KEY BankingDBUserSymmetricKey DECRYPTION BY ASYMMETRIC KEY BankingDBUserAsymmetricKey WITH PASSWORD = '1976' --AsymmetricKey oluşturuyoruz şifre
SELECT
AccountID, FName, LName,
CONVERT(VARCHAR, DecryptByKey(CreditCardType)) AS CreditCardType,
CONVERT(VARCHAR, DecryptByKey(CreditCardNumber)) AS CreditCardNumber,
CONVERT(VARCHAR, DecryptByKey(AccountNotes)) AS AccountNotes
FROM Accounts
CLOSE SYMMETRIC KEY BankingDBUserSymmetricKey
Hiç yorum yok