• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天下

            記錄修行的印記

            對(duì)openssl做的一些簡(jiǎn)單封裝

            #include "stdafx.h"

            int GetRSA(RSA **RsaKeys)
            {
                
            *RsaKeys=RSA_generate_key(RSALEN,RSA_F4,NULL,NULL);
                
            if(NULL==*RsaKeys)
                    
            return -1;
                
            return 0 ;
            }

            //取得私鑰
            int GetPrivateKey(RSA *RsaKeys,RSA **Pvtkey)
            {
                
            *Pvtkey = RSAPrivateKey_dup(RsaKeys);
                
            if(NULL==*Pvtkey)
                    
            return -1
                
            return 0;
            }

            //私鑰To數(shù)據(jù)流
            int PrivateKeyToData(RSA *Pvtkey,unsigned char* bufkey)
            {
                BIO
            * pBio = BIO_new(BIO_s_mem());
                
            if (pBio == NULL) {
                    
            return -1;
                }
                memset(bufkey,
            '\0',RSALEN);
                
            if( i2d_RSAPrivateKey_bio(pBio,Pvtkey) < 0 ) {
                    BIO_free(pBio);    
                    
            return -1;
                }
                BIO_read(pBio,bufkey,RSALEN);

                BIO_free(pBio);    
                
            return 0;
            }

            //數(shù)據(jù)流To私鑰
            int DataToPrivateKey(unsigned char* bufkey,RSA **Pvtkey)
            {
                BIO 
            *pBio = BIO_new(BIO_s_mem());
                
            if (pBio == NULL) {
                    
            return -1;
                }
                BIO_write(pBio,bufkey,RSALEN);
                
            if( NULL == d2i_RSAPrivateKey_bio(pBio,Pvtkey)) {
                    BIO_free(pBio);
                    
            return -1;
                }
                BIO_free(pBio);
                
            return 0;
            }

            //取得公鑰
            int GetPublicKey(RSA *RsaKeys,RSA **Pubkey)
            {
                
            *Pubkey = RSAPublicKey_dup(RsaKeys);
                
            if(NULL==*Pubkey)
                    
            return -1
                
            return 0;
            }


            //公鑰To數(shù)據(jù)流
            int PublicKeyToData(RSA *Pubkey,unsigned char* bufkey)
            {
                BIO 
            *pBio = BIO_new(BIO_s_mem());
                
            if (pBio ==NULL) {
                    
            return -1;
                }
                memset(bufkey,
            '\0',RSALEN);
                
            if(i2d_RSAPublicKey_bio(pBio,Pubkey) < 0) {
                    BIO_free(pBio);
                    
            return -1;
                }
                BIO_read(pBio,bufkey,RSALEN);
                BIO_free(pBio);
                
            return 0;
            }

            //數(shù)據(jù)流To公鑰
            int DataToPublicKey(unsigned char*bufkey,RSA **Pubkey)
            {
                BIO    
            * pBio=BIO_new(BIO_s_mem());
                
            if (pBio ==NULL)
                {
                    
            return -1;
                }
                BIO_write(pBio,bufkey,RSALEN);
                
            if( d2i_RSAPublicKey_bio(pBio,Pubkey) < 0 ) {
                    BIO_free(pBio);    
                    
            return -1;
                }
                BIO_free(pBio);    
                
            return 0;    
            }

            /*公鑰加密->私鑰解密*/
            int RSAPublicEncrypt(RSA *Publickey, char *From, char *To)
            {
                
            int len=0;
                len 
            = RSA_size(Publickey) -11;

                
            if(-1 == (len=RSA_public_encrypt(len,(unsigned char *)From,(unsigned char *)To,Publickey,RSA_PKCS1_PADDING)) )
                    
            return -1;

                
            return len;
            }


            /*私鑰解密<-公鑰加密*/
            int RSAPrivateDecrypt(RSA *Privtekey, char *From, char *To)
            {
                
            if(-1 == (RSA_private_decrypt(RSALEN/8,(unsigned char *)From,(unsigned char *)To,Privtekey,RSA_PKCS1_PADDING)))
                    
            return -1;

                
            return 0;
            }


            /*私鑰加密->公鑰解密*/
            int RSAPrivateEncrypt(RSA *Privtekey, char *From, char *To)
            {
                
            int len = RSA_size(Privtekey)-11;
                
            if(-1 == (len = RSA_private_encrypt(len,(unsigned char *)From,(unsigned char *)To,Privtekey,RSA_PKCS1_PADDING)))
                    
            return -1;

                
            return len;
            }


            /*公鑰解密<-私鑰加密*/
            int RSAPublicDecrypt(RSA *Publickey, char *From, char *To)
            {
                
            if(-1 == (RSA_public_decrypt(RSALEN/8,(unsigned char *)From,(unsigned char *)To,Publickey,RSA_PKCS1_PADDING)) )
                    
            return -1;

                
            return 0;
            }



            //void DesEncrypt(char *Key,char *Msg, char *Result,int Length)
            //{
            //    int             n=0;
            //    DES_cblock      desblock;
            //    DES_key_schedule schedule;
            //
            //    DES_string_to_key(Key,&desblock);
            //    DES_set_key_checked( &desblock, &schedule );
            //
            //    DES_cfb64_encrypt( (unsigned char *)Msg, (unsigned char *)Result,
            //        Length, &schedule, &desblock, &n, DES_ENCRYPT );
            //
            //}
            //
            //
            //void DesDecrypt( char *Key, char *Msg, char *Result,int Length)
            //{
            //
            //    int             n=0;
            //
            //    DES_cblock      desblock;
            //    DES_key_schedule schedule;
            //
            //    DES_string_to_key(Key,&desblock);
            //    DES_set_key_checked( &desblock, &schedule );
            //
            //    DES_cfb64_encrypt( (unsigned char *) Msg, (unsigned char *)Result,
            //        Length, &schedule, &desblock, &n, DES_DECRYPT );
            //
            //}

            void DESGenerateKey(char *pKey)
            {
                
            int nLen=33;
                
            int flag=0;
                
            int i,k=0;

                srand((unsigned)time(NULL));
                
            for(i=0;i<nLen-1;i++)
                {
                    flag
            =rand()%2;
                    
            if(flag)
                        pKey[k
            ++]='A'+rand()%26;
                    
            else
                        pKey[k
            ++]='a'+rand()%26;
                }

                pKey[k]
            ='\0';
            }

            posted on 2014-03-21 17:40 天下 閱讀(1674) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 加密解密

            <2012年8月>
            2930311234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評(píng)論

            91久久福利国产成人精品| 伊人色综合久久天天网| 久久精品水蜜桃av综合天堂| 久久久久久久精品成人热色戒| 日产精品99久久久久久| 国产精品一区二区久久| 国产精品gz久久久| 亚洲欧美日韩久久精品第一区| 亚洲国产成人久久精品动漫| 97精品依人久久久大香线蕉97| av午夜福利一片免费看久久| 久久精品无码一区二区app| 99精品久久精品一区二区| 久久激情亚洲精品无码?V| 99久久综合国产精品免费| 26uuu久久五月天| 久久午夜无码鲁丝片秋霞| 国内精品伊人久久久久影院对白| 亚洲AV日韩精品久久久久| 亚洲国产综合久久天堂| 国产成人精品久久| 国产亚洲精品自在久久| 久久精品国产亚洲av麻豆图片| 开心久久婷婷综合中文字幕| 久久91精品久久91综合| 久久久久人妻精品一区二区三区| 久久亚洲高清综合| 久久久久九九精品影院| 丰满少妇人妻久久久久久4| 97精品国产91久久久久久| 久久亚洲精品无码AV红樱桃| 久久精品人人做人人爽电影| 久久这里都是精品| 伊人久久大香线蕉AV一区二区| 久久人人爽人爽人人爽av| 国产精品免费久久| 无码精品久久一区二区三区| 久久WWW免费人成一看片| 欧美一区二区三区久久综| 久久亚洲精品无码AV红樱桃| 久久久精品国产sm调教网站 |