Giter Site home page Giter Site logo

rhrsautil's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rhrsautil's Issues

rsa验签的时候在通过key获取SecKeyGetBlockSize的时候崩溃。

  • (BOOL)RSAVerifyWithSHA1:(NSData *)signature plainString:(NSString *)plainString publicKey:(NSString *)publickey{
    if (!signature || !plainString || !publickey) {
    NSLog(@"参数不能为空");
    return false;
    }

    SecKeyRef key = [self addPublicKey:publickey];
    size_t signedHashBytesSize = SecKeyGetBlockSize(key);

    // 要验证的签名
    NSData *signatureData = signature;
    const void *signedHashBytes = [signatureData bytes];

    // 待验证的字符串
    NSData *plainData = [plainString dataUsingEncoding:NSUTF8StringEncoding];

    size_t hashBytesSize = CC_SHA1_DIGEST_LENGTH;
    uint8_t *hashBytes = malloc(hashBytesSize);
    if (!CC_SHA1([plainData bytes], (CC_LONG)[plainData length], hashBytes)) {
    return false;
    }

    OSStatus status = SecKeyRawVerify(key,
    kSecPaddingPKCS1SHA1,
    hashBytes, // SHA1签名之后的原字符串
    hashBytesSize, // SHA1签名的长度
    signedHashBytes, // 签名值
    signedHashBytesSize); // 公钥长度(签名值不能超过公钥的长度)

    if(hashBytes) free(hashBytes);

    return status == errSecSuccess;
    }
    大佬,请指点一下,为什么在这个 size_t signedHashBytesSize = SecKeyGetBlockSize(key);
    地方通过key获取size_t的时候崩溃闪退比较多呢。多谢。

黄大佬,这个工具类在使用过程中崩溃,这个项目源码是您亲自写的,能否帮忙看一下,这个工具类不少地方崩溃。

  • (NSData*)rsaDecryptData:(NSData*)data privKey:(NSString * )privKey{
    SecKeyRef key = [MDWRSAUtil addPrivateKey:privKey];
    size_t cipherBufferSize = SecKeyGetBlockSize(key);
    size_t blockSize = cipherBufferSize;
    size_t blockCount = (size_t)ceil([data length] / (double)blockSize);

    NSMutableData *decryptedData = [[NSMutableData alloc] init];

    for (int i = 0; i < blockCount; i++) {
    unsigned long bufferSize = MIN(blockSize , [data length] - i * blockSize);
    NSData *buffer = [data subdataWithRange:NSMakeRange(i * blockSize, bufferSize)];

      size_t cipherLen = [buffer length];
      void *cipher = malloc(cipherLen);
      [buffer getBytes:cipher length:cipherLen];
      size_t plainLen = SecKeyGetBlockSize(key);
      void *plain = malloc(plainLen);
      
      OSStatus status = SecKeyDecrypt(key, kSecPaddingPKCS1, cipher, cipherLen, plain, &plainLen);
      
      if (status != noErr) {
          return nil;
      }
      
      NSData *decryptedBytes = [[NSData alloc] initWithBytes:(const void *)plain length:plainLen];
      [decryptedData appendData:decryptedBytes];
    

    }

    return decryptedData;
    }
    在第四行获取blocksize的时候,捕捉到异常崩溃。请大佬指点迷津,可能是哪里的问题。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.