Encryption in SQL Server 2005
MAK
Encryption is an important method of data security. Sensitive data such as CMT numbers, credit card numbers, passwords . need to be protected against numerous current threats. In SQL Server 2000 you can create your own functions or use external DLLs to encrypt data. In SQL Server 2005, these functions and methods are allowed by default.
SQL Server 2005 provides the following techniques for data encryption
- Encrypt with password
- Encrypt symmetric keys
- Asymmetric key encryption
- Encryption certificate
In the first part of this series, we will explain how to use password encryption and how to decode it.
SQL Server 2005 provides two functions for encryption: one for encryption and one for encryption.
'Password encryption' is a method of encrypting basic data via a password. Data can be decoded if the correct password is used when encrypting. We will try an example of encrypting and decrypting data using password encryption technology.
select EncryptedData = EncryptByPassPhrase ('MAK', '123456789')
Result
EncryptedData
0x0100000000214F5A73054F3AB954DD23571154019F3EFC031ABFCCD258FD22ED69A48002
Now we will execute the Encryptbypassphrase function three times on the following example
declare @count int
declare @SocialSecurityNumber varchar (500)
declare @password varchar (12)
set @count = 1
while @count <= 3
begin
set @SocialSecurityNumber = '123456789'
set @Password = 'MAK'
select EncryptedData = EncryptByPassPhrase (@password, @SocialSecurityNumber)
set @ count = @ count + 1
end
Result
EncryptedData
0x01000000CBB7EE45B5C1460D6996B149CE16B76C7F7CD598DC56364D106B05D47B930093
(1 row (s) affected)
EncryptedData
0x010000005E884D30C8FF7E4723D4E70A03B0B07F877667BAF1DA9BE1E116434842D11B99
(1 row (s) affected)
EncryptedData
0x01000000C508FB0C4FC7734B47B414D2602A71A338417DD685229173684D319334A084CD
Note :
'123456789' here may be credit card number and 'MAK' is the password
The results of the Encryptbypassphrase after each function execution are different. However, when you decrypt the data, it still produces the original result before encoding.
Now we will try to decrypt the above encrypted data with the DecryptByPassPhrase function
select convert (varchar (100), DecryptByPassPhrase ('MAK', 0x01000000CBB7EE45B5C1460D6996B149CE16B76C7F7CD598DC56364D106B05D47B930093))
select convert (varchar (100), DecryptByPassPhrase ('MAK', 0x010000005E884D30C8FF7E4723D4E70A03B0B07F877667BAF1DA9BE1E116434842D11B99))
select convert (varchar (100), DecryptByPassPhrase ('MAK', 0x01000000C508FB0C4FC7734B47B414D2602A71A338417DD685229173684D319334A084CD))
Result
123456789
(1 row (s) affected)
123456789
(1 row (s) affected)
123456789
(1 row (s) affected)
Try decrypting the encrypted data with another password. Execute according to the following statement
select convert (varchar (100), DecryptByPassPhrase ('test', 0x01000000C508FB0C4FC7734B47B414D2602A71A338417DD685229173684D319334A084CD))
Result
NULL
(1 row (s) affected)
The result shows you that SQL Server returns NULL if the password is wrong.
Now we will try to create a table containing credit card numbers and CMT numbers, then encrypt this data via password encryption.
USE [master]
GO
/ ****** Object: Database [admin] Script Date: 11/25/2007 10:50:47 ****** /
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'Customer DB ')
DROP DATABASE [Customer DB]
go
create database [Customer DB]
go
use [Customer DB]
go
create table [Customer data]
([customer id] int,
[Credit Card Number] bigint,
[Social Security Number] bigint)
go
insert into [Customer data] values (1, 1234567812345678, 123451234)
insert into [Customer data] values (2, 1234567812345378, 323451234)
insert vào [Customer data] values (3, 1234567812335678, 133451234)
insert into [Customer data] values (4, 1234567813345678, 123351234)
insert into [Customer data] values (5, 1234563812345678, 123431234)
go
Create two columns to save the encrypted data
use [Customer DB]
go
alter table [Customer Data] add
[Encrypted Credit Card Number] varbinary (MAX)
go
alter table [Customer Data] add
[Encrypted Social Security Number] varbinary (MAX)
go
Update the encrypted data into the two columns you just created
use [Customer DB]
go
update [Customer Data] set [Encrypted Credit Card Number] =
EncryptByPassPhrase ('Credit Card', convert (varchar (100), [Credit Card Number]))
go
update [Customer Data] set [Encrypted Social Security Number] =
EncryptByPassPhrase ('Social Security', convert (varchar (100), [Social Security Number]))
Go
Trace the table with the following commands (Figure 1)
use [Customer DB]
go
select * from [customer data]
go
Result
Figure 1
Delete columns that contain unencrypted data
use [Customer DB]
go
alter table [Customer Data] drop column [Credit Card Number]
go
alter table [Customer Data] đã thoát cột [Social Security Number]
go
Query the table according to the following commands (Figure 2)
use [Customer DB]
go
select * from [customer data]
go
Result
Figure 2
Decrypt the data on the table via the Decryptbypassphrase function as follows (Figure 3)
use [Customer DB]
go
select
[customer id],
convert (bigint, convert (varchar (100), decryptbypassphrase ('Credit Card', [Encrypted Credit Card Number])))
[Credit Card Number],
convert (bigint, convert (varchar (100), decryptbypassphrase ('Social Security', [Encrypted Social Security Number])))
[Social Security Number] from [customer data]
Go
Result
customer id, Credit Card Number, Social Security Number
1, 1234567812345678, 123451234
2, 1234567812345378, 323451234
3, 1234567812335678, 133451234
4, 1234567813345678, 123351234
5, 1234563812345678, 123431234
Figure 3
Conclude
Data encryption is really important. In this article, I have introduced you to one of the four encryption techniques available in SQL Server 2005 - password encryption technology - and how to decode it. In the following article, we will discuss the method of hacking / recovering data encrypted with this password.
You should read it
- Set password, password protect USB data safely
- Ways to set USB passwords for data protection
- What is data encryption? Things to know about data encryption
- 5 popular encryption algorithms you should know
- Top 20 best encryption software for Windows
- What is Zero-Knowledge Encryption? Why use this type of encryption?
- What is end-to-end encryption? How does it work?
- Top 5 best USB encryption software
May be interested
- Check email encryption processto facilitate this analysis, it is good to 'talk' directly to your smtp or imap server.
- Google raises data security with 2048 bit encryptionin a message released on monday, google said it would transfer all certificates to use 2048 bit encryption. the certificates are used to encrypt the communication between the server and the user's web browser.
- File encryption software and privacy protection messagesrecently, reports have shown that technology spying is on the rise. therefore, it is necessary to protect your data and privacy with encryption software. the following article will introduce you to some great encryption software for windows, ios and android.
- How to enable Full-Disk Encryption on Windows 10?on windows 10, some use encryption by default, but some do not. in the following article, network administrator will show you how to check if the memory on windows 10 computer is encrypted.
- How to set up military-grade encryption on Windows 11military-grade encryption is a term marketers use to describe aes. aes itself stands for 'advanced encryption standard', a very secure way to encrypt digital data.
- Install Cherokee with PHP5 and MySQL supported in Fedora 14currently, cherokee is one of the lightest web server, high flexibility and easy to configure and set up. in addition, it also supports many advanced technology platforms such as fastcgi, scgi, php, cgi, encryption connecting tls and ssl protocols, virtual hosts, encryption mechanisms, load balancing of resources, data data of the system, apache log file ...
- How to encrypt text using the Text Encryption Tooltext encryption tool is a text encryption utility with sha-256 algorithm, which helps you quickly encrypt or decode text.
- Instructions for USB encryption with VeraCryptusb (removable drive) is a place to store your important files. what will happen if you lose it? the result will be extremely bad so it is better to encrypt your usb. in this article, tipsmake.com will guide you how to simple and effective usb encryption.
- How to encrypt emailif not encrypted, your email is at risk of being hacked and read at any time, or you may lose your account. this article will give you an overview of how to encrypt email, help you understand and choose the right encryption solution.
- Microsoft changes the default settings to keep the content stored on the hard drive safein june last year, security researchers discovered that the method of securing ssd hard drive encryption could be easily 'broken' ...