OC加密

作者: ning_e83f | 来源:发表于2023-02-06 09:26 被阅读0次

    1、DES加密

    -(NSString*)encryptDES:(NSString*)plainText{

        NSString *key = @"AsdFGhjKLqWErtYuioPZxcvB";

        NSString*iv =@"12345678";

        NSString*ciphertext =nil;

        NSData *textData = [plainText dataUsingEncoding:NSUTF8StringEncoding];

        NSUIntegerdataLength = [textDatalength];

        size_tbufferSize = dataLength +kCCBlockSizeDES;

        void*buffer =malloc(bufferSize);

        memset(buffer,0,sizeof(char));

        size_tnumBytesEncrtpted =0;

        CCCryptorStatuscryptStatus =CCCrypt(kCCEncrypt,kCCAlgorithmDES,kCCOptionPKCS7Padding, [keyUTF8String],kCCBlockSizeDES, [ivUTF8String], [textDatabytes], dataLength, buffer, bufferSize, &numBytesEncrtpted);

        if(cryptStatus ==kCCSuccess){

            NSData*data = [NSDatadataWithBytes:(constvoid*)bufferlength:(NSUInteger)numBytesEncrtpted];

            ciphertext = [GTMCCBBase64stringByEncodingData:data];

        }

        returnciphertext;

    }

    相关文章

      网友评论

          本文标题:OC加密

          本文链接:https://www.haomeiwen.com/subject/ofqtkdtx.html