I created stored function with encryption.
after i created i dont able to view the source code from system tables or any tool.
i have get back the original source code
note: i want to stored function not for stored procedure.
I have created two user defined functions for encryption and decryption using passphrase mechanism. When I call encryption function, each time I am getting the different values for the same input. While I searching a particular value, it takes long time to retrieve due to calling decryption function for each row.
best way to encrypt and decrypt using user defined functions.Below is the query which is taking long time.
SELECT ID FROM table WITH (NOLOCK) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WHERE dbo.DecodeFunction(column) = 'value'
When I try to use symetric or asymetric encryption, I am not able to put "OPEN SYMETRIC KEY" code in a function. So, I am using PassPhrase mechanism.
I would like to be able to store user network passwords in a database table and be able to encrypt and decrypt using stored procs. Could anyone give me a pointer on this.
This function is used to initialize the seed for the RC4 algorithmCREATE FUNCTION dbo.fnInitRc4 ( @Pwd VARCHAR(256) ) RETURNS @Box TABLE (i TINYINT, v TINYINT) AS
BEGIN DECLARE@Key TABLE (i TINYINT, v TINYINT)
DECLARE@Index SMALLINT, @PwdLen TINYINT
SELECT@Index = 0, @PwdLen = LEN(@Pwd)
WHILE @Index <= 255 BEGIN INSERT@Key ( i, v ) VALUES( @Index, ASCII(SUBSTRING(@Pwd, @Index % @PwdLen + 1, 1)) )
INSERT@Box ( i, v ) VALUES( @Index, @Index )
SELECT@Index = @Index + 1 END
DECLARE@t TINYINT, @b SMALLINT
SELECT@Index = 0, @b = 0
WHILE @Index <= 255 BEGIN SELECT@b = (@b + b.v + k.v) % 256 FROM@Box AS b INNER JOIN@Key AS k ON k.i = b.i WHEREb.i = @Index
SELECT@t = v FROM@Box WHEREi = @Index
UPDATEb1 SETb1.v = (SELECT b2.v FROM @Box b2 WHERE b2.i = @b) FROM@Box b1 WHEREb1.i = @Index
UPDATE@Box SETv = @t WHEREi = @b
SELECT@Index = @Index + 1 END
RETURN ENDANd this function does the encrypt/decrypt partCREATE FUNCTION dbo.fnEncDecRc4 ( @Pwd VARCHAR(256), @Text VARCHAR(8000) ) RETURNSVARCHAR(8000) AS
BEGIN DECLARE@Box TABLE (i TINYINT, v TINYINT)
INSERT@Box ( i, v ) SELECTi, v FROMdbo.fnInitRc4(@Pwd)
Hi, Does any body have a stored procedure or a function I can use? What I need is to encrypt and decrypt a password using Tiny Encryption Algorithm, SO I have an encryption scalar valued function or sproc and similarly decryption function or sproc.Now I need rolling keys to encrypt and decrypt, so I have a table which has keys used for encryption and decryption and depending on the dtae the keys are different.So I alos need a sproc to retrieve the keys.If anybody has done it before or can point me to where can I go let me know?
Database Security, we are going to use AES 256 Symmetric Encryption. We will be using RSA for Asymmetric Key Encryption, 1024 Bits.
We got the code working for the seond case but for the first, WHEN:
CREATE SYMMETRIC KEY sym_Key WITH ALGORITHM = AES_256 ENCRYPTION BY ASYMMETRIC KEY asym_Key GO
THEN:
-- Msg 15314, Level 16, State 1, Line 1 -- Either no algorithm has been specified or the bitlength and the algorithm specified for the key are not available in this installation of Windows.
What can be the way out to be able to create the AES 256 Symmetric key.
I am planning to use XP_CRYPT for encrypting and decrypting cc#'s, passwords etc., at database level. Any suggestions or experiences on this. More info about this product at http://www.activecrypt.com/faq.htm
Hi. I have a SQL Server 2000 database that contains information I would like to encrypt. The information is a field inside a table, and I would like to encrypt this information using a key, and decrypt it in my asp.net application using that key and use the decrypted data. Please tell me how this can be done, or direct me to an article or a link on the subject. Thanks in advance.
I have created mirroring... one of the column is encrypted on mirror database and I can see the decrypted result when I do query when I actually logged into server (through remote connection) but when I use the same query through using SSMS from my laptop the query result come as the column is not decrypted,
Hey I had a table with a column of data encrypted in a format. I was able to decrypt it and then encrypt it using Symmetric keys and then updating the table column with the data. Now, there is a user sp which needs to encrypt the password for the new user and put it in the table. I'm not being able to make it work. I have this so far. Something somewhere is wrong. I dont know where. Please help Thanks. I used the same script to do the encryption initially but that was for the whole column. I need to see the encrypted version of the @inTargetPassword variable. But it's not working. It doesn't give me an error but gives me wrong data...
I want to perform column level and database level encryption/decryption.... Does any body have that code written in C# or VB.NET for AES-128, AES-192, AES-256 algorithms... I have got code for single string... but i want to encrypt/decrypt columns and sometimes the whole database... Can anybody help me out... If you have Store procedure in SQL for the same then also it ll do... Thanks in advance
Is there anyway by which I can decrypt the encrypted Stored Procedures which the Previus DBA had written and its running in Production . I need to make some changes to the Stored Procedure. Is is possible
Hi, I created the stored procedure with encryption and now I want to see the same procedure but I am not able to see the text of procedure with SP_HELPTEXT command. Please help so that I could see my stored procedure with sp_helptext command. Thanks.
My command was: sp_helptext dm_sp_Outstanding_Events
Error message:
The text for object 'dm_sp_Outstanding_Events' is encrypted.
Hi, I would like to create a stored procedure, which accept RunAsUser, MasterKeyPassword and also ASymmetricKeyPassword. In this stored procedure, it call OPEN MASTER KEY and etc. I put these code in stored procedure so that my support staff can call it when doing maintenance by passing the parameter. I don't expect them to remember OPEN MASTER KEY and etc syntax.
However, I hit error "Invalid Syntax" when I run my code as below. Any ideas?
Thank you
-- ================================================ -- Template generated from Template Explorer using: -- Create Procedure (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the procedure. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= CREATE PROCEDURE GrantMe -- Add the parameters for the stored procedure here @RunAsUser varchar(20), @MasterKey varchar(30), @ASKey varchar(30) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;
EXEC AS USER=@RunAsUser;
OPEN MASTER KEY DECRYPTION BY PASSWORD=@MasterKey;
OPEN SYMMETRIC KEY HRMS DECRYPTION BY ASYMMETRIC KEY FlexHRMS WITH PASSWORD=@AsKey ; END GO
I am search for coding criteria I need create a stored procedure with execute as and along with encryption. How can I use the same ? My main motive is to create proc with execute as a user also at the same time I need to encrypt the same from other users seeing the code.
The below query is getting errors:
Create procedure testproc with execute as 'user' and with encryption as truncate table some table
I have been testing two way symmetrical encryption. I have been able to encrypt rows of a spacific column using the following UPDATE statement, however, when I try and decrypt them, the query returns Null for the effected rows. Can anyone see where I may have gone wrong in the decryption statement?UPDATE tblReceipts SET tblReceipts.CCNumber = EncryptByPassPhrase('Abracadabra!1234$',tblReceipts.CCNumber) FROM tblReceipts WHERE tblReceipts.CreditCardType > 0
Decrypt Does Not Work?????
SELECT CONVERT(varchar, DecryptByPassPhrase('Abracadabra!1234$',tblReceipts.CCNumber)) AS CCNumber FROM tblReceipts WHERE tblReceipts.CLIENTID = 15000My CCNumber field is nvarchar(20)My PassPhrase is just a test phraseThe data after it is encrypted in just a bunch of binary looking boxes
How do I tell SQL Server what key to use for DES3 decryption? I want to encrypt in Oracle and after ETL to SQL Server, be able to decrypt but keep a column's value encrypted in Oracle, SSIS and SQL side - only decrypting on the SQL Server side when needing to use the value.
I wanted to configure Report Server and publish my reports. I configured report server 2005 on win 2003 os. I prepared few reports and deployed them. When I tried to view this report thru ReportServer (http://localhost/ReportServer) from my local machine, I got the following error message:- The encrypted value for the "UnattendedExecutionAccountPassword" configuration setting cannot be decrypted.
The report server has encountered a configuration error. See the report server log files for more information. Can anyone help me in solving this! I will highly appreciate it.
I'm trying to put together a proof of concept utilizinf encryption with SQL Server and neded to get a little help. I've got the basics down but I'm not seeing the expected results. Here's the script that I'm running against a very simple table. I'm essentially just adding a coulmn to hose encrypted data, encrypting that data, and then selecting that data - in both encrypted and decrypted form:
Code Block CREATE CERTIFICATE LAND_ENCRYPT_ACCOUNT3 WITH SUBJECT = 'ExternalAccountID'; GO CREATE SYMMETRIC KEY AccountID3_01 WITH ALGORITHM = AES_128 ENCRYPTION BY CERTIFICATE LAND_ENCRYPT_ACCOUNT3; GO USE [LAND_ENCRYPT]; GO -- Create a column in which to store the encrypted data. ALTER TABLE Account ADD EncryptedAccountID3 varbinary(128); GO -- Open the symmetric key with which to encrypt the data. OPEN SYMMETRIC KEY AccountID3_01 DECRYPTION BY CERTIFICATE LAND_ENCRYPT_ACCOUNT3; -- Encrypt the value in column NationalIDNumber with symmetric -- key SSN_Key_01. Save the result in column EncryptedNationalIDNumber. UPDATE Account SET EncryptedAccountID3 = EncryptByKey(Key_GUID('AccountID3_01'), ExternalAccountID); GO -- Verify the encryption. -- First, open the symmetric key with which to decrypt the data. OPEN SYMMETRIC KEY AccountID3_01 DECRYPTION BY CERTIFICATE LAND_ENCRYPT_ACCOUNT3; GO -- Now list the original ID, the encrypted ID, and the -- decrypted ciphertext. If the decryption worked, the original -- and the decrypted ID will match. SELECT ExternalAccountID, EncryptedAccountID3 AS 'Encrypted ID Number', CONVERT(nvarchar, DecryptByKey(EncryptedAccountID3)) AS 'Decrypted ID Number' FROM Account; GO
But when I run the "decrypt" the data, the only character that appears unencrypted is the very last character of each account number:
ExternalAccountID Encrypted ID Number Decrypted ID Number
The first value is the unencrypted account id, the second is the encrypted account id, the last is the decrypted account id. As you can see, the decrypted value isn't quite right.
I've tried the AES_256, DES, and AES_128 algorithms and they all yield the same result.
Am I missing something?
Also, if I'm going to be inserting into an encrypted column, do I need to do it via a view and a trigger, or can I just do a straight forward INSERT / UPDATE?
I get a strange error on my SQL Server 2005 database when I try to start replication.
Here is the manipulation leading to my problem: 1. Install new Windows server 2003 and SQL Server 2005 STD, service pack 2. Server is part of a domain. SQL2k5 is running under the LocalSystem account on each machine. 2. Get a copy of yesterday's full backup and transaction logs from running production SQL2k5 server. 3. Restore master, model, msdb and other user databases. 4. Try to start replication using the wizard. I get the following error message
Msg 15466 sp_addlinkedsrvlogin An error occurred during decryption. Msg 15185 no remote user distributor_admin
I suspect this problem has to do with master service keys but need some advice. I am not sure it is related to the master restore since it also occurs on the production machine.
Sql server 2008R2 (SP2) Ent, PROD DB myDB was encrypted. During Release mistakenly (Vendor created script blames some settings in ...- actually does not matter) Decryption started (ALTER .. SET ENCRYPTION OFF) as we got from ErrorLog.
For some reason initial encryption scan was aborted and then mentioned command: ALTER ... OFF was issued again. What we have now (after 60 h of decryption- encryption took only 2.5 h)- is_encrypted = 0 in sys.databases, encryption_state = 5 (decryption in progress) in sys.dm_database_encryption_keys (percent_complete= 0). But it seems myDB is still encrypted- I made a backup of myDB and tried to read it (restore filelistonly) from other server (with no encryption)- failed- asked for key. Seems metadata was changed when initial scan during decryption started but then stuck and (if I am correct) decryption was never completed. Question- any similar experience? How we can fix meta- data, i.e. assuming that myDB is still encrypted we should have is_encrypted = 1 and encryption_state = 3 (encrypted).