• 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

  • 相关阅读:
    彭明辉教授-《研究生完全求生手册》
    使用npm创建一个命令行工具
    #!/usr/bin/python与#!/usr/bin/env python的区别
    使用node+express搭建第一个node后端项目
    使用npm创建一个程序库包
    多项式多点求值
    2. 两数相加
    CSS实现子元素自动充满父元素的剩余空间
    侧边导航栏滚动条---CSS overflow实现
    Asp.NET Core简介
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2763288.html
Copyright © 2020-2023  润新知