zt自己动手用工行U盾加密自己私有文件

本文介绍了一种利用工商银行U盾进行文件加密的方法,通过Windows Crypto API实现对称密钥的保护,确保文件的安全性。

原文url: http://www.bigsea.com.cn/archives/821/

 

 

zt自己动手用工行U盾加密自己私有文件

No Comments | 安全技术 | by bigsea | 4788 Views. | 2008, November 26, 5:59 PM 本帖子原来是fleshwound的投稿文章,被root转入论坛。

作者:ecceccecc
URL:http://www.smatrix.org

   网上的文件加密 软件多如牛毛,文件加密的核心是对对称密钥的保护。网上基于口令的文件加密很弱的,自己动手用工行u盾 可以做一个文件加密程序,绝对的安全。AES大家goole上一找就行了。对称密钥核心部分用下面的代码就可以了。


#include <windows.h>
#include <tchar.h>
#include <wincrypt.h>
#include <stdio.h>




int _tmain(int argc, _TCHAR* argv[])
{
    HCRYPTPROV hProv;
    HCRYPTKEY  hKey;
    BYTE *pbKeyBlob = NULL;
    DWORD dwBlobLen;
    BYTE *pbData = NULL;
    DWORD cbData;
    DWORD i;
    
    
    //LPTSTR MSCSP=TEXT("Logoxin CSP v1.0");
    //LPSTR MSACSP="Logoxin CSP v1.0";
    
    LPTSTR MSCSP=TEXT("SafeSign CSP Version 1.0");
    LPSTR MSACSP="SafeSign CSP Version 1.0";
    
    
    BYTE pbBuffer[128];
    BYTE *pbConst= (BYTE *)"The data that is to be Encrypted.";
    DWORD dwBufferLen = (DWORD)strlen((char *)pbConst)+1;
    memcpy(pbBuffer,pbConst,dwBufferLen);


    if(!CryptAcquireContext(&hProv, NULL, MSCSP, PROV_RSA_FULL, 0))
        printf("Error %x CryptAcquireContext!n", GetLastError());


    if(!CryptGetProvParam(hProv, PP_ENUMCONTAINERS, pbData, &cbData, CRYPT_FIRST))
        printf("Error %x CryptGetProvParam!n", GetLastError());

    pbData = new BYTE[cbData];

    //Get the Container Name
    if(!CryptGetProvParam(hProv, PP_ENUMCONTAINERS, pbData, &cbData, CRYPT_FIRST))
        printf("Error %x CryptGetProvParam!n", GetLastError());

    //ReleaseContext
      if(!CryptReleaseContext(hProv,0))
        printf("Error %x during ReleaseContext!n", GetLastError());

      
     //Get the Container
     if(!CryptAcquireContextA(&hProv, (LPCSTR)pbData, MSACSP, PROV_RSA_FULL, 0))
        printf("Error %x CryptAcquireContext!n", GetLastError());

    if(!CryptGetUserKey(hProv,AT_KEYEXCHANGE,&hKey))
        printf("Error %x CryptGetUserKey!n", GetLastError());

    
    // Determine the size of the key BLOB and allocate memory.
    if(!CryptExportKey(hKey, 0, PUBLICKEYBLOB , 0, NULL, &dwBlobLen))
        printf("Error %x computing BLOB length!n", GetLastError());
    if((pbKeyBlob = (BYTE *)malloc(dwBlobLen)) == NULL)
         printf("Out of memory!n");
  
    // Export the key into a simple key BLOB.
     if(!CryptExportKey(hKey, 0, PUBLICKEYBLOB , 0, pbKeyBlob, &dwBlobLen))
         printf("Error %x during CryptExportKey!n", GetLastError());

     //Encrypt PlainText
     if(!CryptEncrypt(hKey,NULL,TRUE,0,pbBuffer,&dwBufferLen,128))
         printf("Error %x during CryptEncrypt!n", GetLastError());

     printf("the Ciper isn");
     for(i=0;i<dwBufferLen;i++)
         printf("%02X",pbBuffer);
     printf("n");

    
     //Decrypt CipherText
     if(!CryptDecrypt(hKey,NULL,TRUE,0,pbBuffer,&dwBufferLen))
          printf("Error %x during CryptDecrypt!n", GetLastError());

     printf("the Plain  isn");
     for(i=0;i<dwBufferLen;i++)
         printf("%c",pbBuffer);
     printf("n");


    
     if(hKey)
     {
         if(!CryptDestroyKey(hKey))
             printf("Error %x during CryptDestoryKey!n", GetLastError());

     }


    
    
     //ReleaseContext
      if(!CryptReleaseContext(hProv,0))
        printf("Error %x during ReleaseContext!n", GetLastError());


      
    
      return 1;
}
(你可以随意转载,但请保留原作者信息,有任何关于密码学和USBKEY,网银的问题可以来交流!
by ecceccecc)

在Java中,zt-zip库是一个用于处理ZIP文件的工具包,它可以帮助你读取、创建、修改和删除ZIP档案中的内容,包括获取文件目录。以下是使用zt-zip获取ZIP文件目录的基本步骤: 首先,你需要添加zt-zip的依赖到你的项目中。如果你使用Maven,可以在pom.xml文件中添加如下依赖: ```xml <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <!-- Update the version number as per the latest release --> <version>0.1.56</version> </dependency> ``` 然后,你可以通过以下代码来获取ZIP文件的目录结构: ```java import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSch; import com.jcraft.jsch.Session; public void listZipDirectory(String zipFilePath) throws Exception { JSch jsch = new JSCH(); Session session = jsch.getSession("username", "localhost", 22); // Replace with your server details session.setPassword("password"); // Replace with your password session.setConfig("StrictHostKeyChecking", "no"); session.connect(); ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); channel.connect(); try { String directoryPath = channel.cd(zipFilePath); if (!channel.ls(directoryPath).isEmpty()) { for (String entry : channel.ls(directoryPath)) { System.out.println(entry); } } else { System.out.println("The directory is empty or not found."); } } finally { channel.disconnect(); session.disconnect(); } } ``` 在这个例子中,`ls(directoryPath)`方法会返回一个包含目录下所有文件和子目录名的列表。记得替换"username"、"localhost"和"password"为你实际的SSH连接信息。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值