• SQL SERVER 2008密码,凭证学习


    密码,凭证学习

    --单纯的加密解密函数

    declare

    @plain_text nvarchar(1000),

    @enc_text varbinary(2000);

    SET @plain_text=N'Ask not what your contrycan do for you...';

    SET @enc_text=EncryptByPassPhrase(N'E Pluribus Unum',@plain_text);

    SELECT 'Original plain text=',@plain_text;

    SELECT 'Encrypted text=',@enc_text; SELECT 'Decrypted text=',CAST(DecryptByPassPhrase(N'E Pluribus Unum',@enc_text) as nvarchar(1000));

    use AdventureWorksLT2008 /*创建证书*/

    CREATE CERTIFICATE SampleCert  

    Encryption by PASSWORD =N'p$@1k-#z'   WITH SUBJECT=N'Sample Certificate',  

    EXPIRY_DATE=N'10/31/2026'    

    BACKUP CERTIFICATE SampleCert  TO FILE=N'C:\MK\BackupSampleCert.cer'  WITH PRIVATE KEY (   FILE=N'C:\MK\BackupSampleCert.pvk',   ENCRYPTION BY PASSWORD=N'p@$$word',   DECRYPTION BY PASSWORD=N'p$@1k-#z'  );    

    //删除证书  DROP CERTIFICATE SampleCert;  

    GO  

    /*恢复已备份的证书和私钥*/ 

    CREATE CERTIFICATE SampleCert  FROM FILE=N'C:\MK\BackupSampleCert.cer'  WITH PRIVATE KEY(   

    FILE=N'C:\MK\BackupSampleCert.pvk',   

    DECRYPTION BY PASSWORD=N'p@$$word',   

    ENCRYPTION BY PASSWORD=N'p$@1k-#z' );  

    GO 

    USE AdventureWorksLT2008; GO

    --Initialize the plain text

    DECLARE @plain_text nvarchar(58);

    SET @plain_text=N'This is a test1';

    PRINT @plain_text;

    --加密

    DECLARE @Cipher_text Varbinary(127)

    SET @Cipher_text=ENCRYPTBYCERT(Cert_ID(N'SampleCert'),@plain_text);

    PRINT @Cipher_text

    --解密

    SET @plain_text=CAST(DecryptByCert(Cert_ID(N'SampleCert'),@Cipher_text,   N'p$@1k-#z') as nvarchar(58));

    PRINT @plain_text;

    GO

  • 相关阅读:
    安装MSSQL2008出现的问题记录
    制作安装包遇到的问题
    算法设计方法动态规划
    基础果然要牢记(一次失败的电面)
    搜狗垂搜笔试
    几种堆的时间复杂度分析
    正则表达式转NFA
    组合数学(1)
    算法设计方法贪心算法
    最短路径问题
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2763288.html
Copyright © 2020-2023  润新知