当前位置: 编程技术>移动开发
本页文章导读:
▪asList 后的remove错误 asList 后的remove异常
同样下面两组代码
情况一:
rUidList = new ArrayList<String>();
rUidList.add("1");
rUidList.add("2");
rUidList.add("3");
rUidList.remove(“1”);
情况二:
String str = "1,2,3,4";
rUidList = Arra.........
▪ [OpenSSL][原]取得文件签名 [OpenSSL][原]获得文件签名
测试数据链接:http://jacky-dai.iteye.com/admin/blogs/1743774
#include <openssl/rsa.h>
#include <openssl/evp.h>
#pragma comment(lib, "libeay32.lib")
void ReverseBuffer(unsigned char *pBuf, u.........
▪ [MS Crypt API][原]计算资料hashParam [MS Crypt API][原]计算文件hashParam
#define SAIO_CSP "SAIO SignCSP"
typedef enum Em_Algorithm_TYPE
{
AlgorithmType_SHA1 = 1,
AlgorithmType_SHA256 = 2
}ALGORITHM_TYPE, *PALGORITHM_TYPE;
BOOL GetFile.........
[1]asList 后的remove错误
来源: 互联网 发布时间: 2014-02-18
asList 后的remove异常
同样下面两组代码
情况一:
rUidList = new ArrayList<String>();
rUidList.add("1");
rUidList.add("2");
rUidList.add("3");
rUidList.remove(“1”);
情况二:
String str = "1,2,3,4";
rUidList = Arrays.asList(str.split(","));
rUidList.remove(“1”);
情况一:没有问题
情况二:报Exception in thread "main" java.lang.UnsupportedOperationException
这个java的一个bug吧。没有找到第二种情况为什么错??哪位大侠知道为什么第二种情况报错。
1 楼
yangfuchao418
前天
http://www.cnblogs.com/zolra/archive/2011/03/02/1969235.html
[2] [OpenSSL][原]取得文件签名
来源: 互联网 发布时间: 2014-02-18
[OpenSSL][原]获得文件签名
测试数据链接:http://jacky-dai.iteye.com/admin/blogs/1743774
测试数据链接:http://jacky-dai.iteye.com/admin/blogs/1743774
#include <openssl/rsa.h> #include <openssl/evp.h> #pragma comment(lib, "libeay32.lib") void ReverseBuffer(unsigned char *pBuf, unsigned long ulLen) { if(0 == ulLen) { return; } //char tmp; unsigned char ucTemp; for(unsigned long i = 0, j = ulLen-1; i < ulLen/2; i++, j--) { ucTemp = pBuf[i]; pBuf[i] = pBuf[j]; pBuf[j] = ucTemp; } } void OpenSSLGenFileSignature_byFile() { RSA* rsa = RSA_new(); MSkeyConvertToOpenSSLKey("Test_1024_Key.prv", *rsa); EVP_PKEY *evpKey = EVP_PKEY_new(); //新建一个EVP_PKEY变量 EVP_PKEY_set1_RSA(evpKey, rsa); const EVP_MD* algrothm = EVP_sha1(); EVP_MD_CTX mdctx; EVP_MD_CTX_init(&mdctx); EVP_VerifyInit_ex(&mdctx, algrothm, NULL); byte file[512] = {0}; DWORD dwFileSize = sizeof(file); ReadBufferFromFile("PublicKey.bin", file, &dwFileSize); EVP_SignUpdate(&mdctx, file, dwFileSize); BYTE signValue[128] = {0}; UINT signLen = 0; EVP_SignFinal(&mdctx, signValue, &signLen, evpKey); EVP_MD_CTX_cleanup(&mdctx); EVP_PKEY_free(evpKey); RSA_free(rsa); } void OpenSSLGenFileSignature_byFileHash() { RSA* rsa = RSA_new(); MSkeyConvertToOpenSSLKey("Test_1024_Key.prv", *rsa); const EVP_MD* algrothm = EVP_sha1(); byte byHashData[32] = {0}; DWORD dwHashSize = sizeof(byHashData); ReadBufferFromFile("HashData.bin", byHashData, &dwHashSize); ReverseBuffer(byHashData, dwHashSize); byte bySignedBuf[512] = {0}; UINT nSignSize = 0; int nRet = RSA_sign(algrothm->type, byHashData, (UINT)dwHashSize, bySignedBuf, &nSignSize, rsa); RSA_free(rsa); }
[3] [MS Crypt API][原]计算资料hashParam
来源: 互联网 发布时间: 2014-02-18
[MS Crypt API][原]计算文件hashParam
#define SAIO_CSP "SAIO SignCSP" typedef enum Em_Algorithm_TYPE { AlgorithmType_SHA1 = 1, AlgorithmType_SHA256 = 2 }ALGORITHM_TYPE, *PALGORITHM_TYPE; BOOL GetFileHashParam(LPCSTR lpszCataFileName, PBYTE pbyHash, PDWORD pdwHashLen, ALGORITHM_TYPE emAlAlgorithmType) { BOOL bRet = FALSE; HCRYPTPROV hProv = 0; HCRYPTHASH hHash = 0; HCRYPTKEY hKey = 0; HANDLE hFile = NULL; DWORD dwFileSize = 0, len; BYTE byTempBuf[2049] = {0}; hFile = CreateFile(lpszCataFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == hFile) { return FALSE; } DWORD dwProvType = PROV_RSA_AES; ALG_ID hashAlgo = CALG_SHA_256; if (AlgorithmType_SHA1 == emAlAlgorithmType) { dwProvType = PROV_RSA_FULL; hashAlgo = CALG_SHA1; } if (!CryptAcquireContext(&hProv, SAIO_CSP, NULL, dwProvType, 0)) { if (GetLastError() == NTE_BAD_KEYSET) { if(!CryptAcquireContext(&hProv,SAIO_CSP,NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) { goto HashExit; } } } // // Create a hash object. // DWORD dwError = 0; if ( !CryptCreateHash(hProv, hashAlgo ,0 ,0 ,&hHash)) { dwError = GetLastError(); goto HashExit; } dwFileSize = GetFileSize(hFile, NULL); while(dwFileSize != 0) { bRet = ReadFile(hFile, byTempBuf, 2048, &len, NULL); // // Check for end of file. // if (bRet && len==0) { break; } CryptHashData(hHash, byTempBuf, len, 0); dwFileSize -= len; } if (hFile != NULL) { CloseHandle(hFile); } len = 0; DWORD dwCount = sizeof(DWORD); if(!CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE*)pdwHashLen, &dwCount, 0)) { *pdwHashLen = 0; } else { if (!CryptGetHashParam(hHash, HP_HASHVAL, pbyHash, pdwHashLen, 0)) { *pdwHashLen = 0; } } if (*pdwHashLen != 20 && *pdwHashLen != 32) { bRet = FALSE; } HashExit: if (hKey != NULL) { CryptDestroyKey(hKey); } if (hHash != NULL) { CryptDestroyHash(hHash); } if (hProv != NULL) { CryptReleaseContext(hProv, 0); } return bRet; }
最新技术文章: