Encrypt in Objective-C / Decrypt in Ruby using anything

前端 未结 4 1315
梦如初夏
梦如初夏 2021-01-01 07:26

We are using this code to encrypt in Objective-C on the iPhone:

- (NSMutableData*) EncryptAES: (NSString *) key
{
    char keyPtr[kCCKeySizeAES128+1];
    bz         


        
4条回答
  •  清酒与你
    2021-01-01 07:45

    You could as well use the following libs providing in-built AES-256-CBC cipher and Base64 encoding that you can use across both platforms quickly:

    Ruby

    https://github.com/Gurpartap/aescrypt

    Here's how you would use the AESCrypt Ruby gem:

    message = "top secret message"
    password = "p4ssw0rd"
    
    # Encrypting
    encrypted_data = AESCrypt.encrypt(message, password)
    
    # Decrypting
    message = AESCrypt.decrypt(encrypted_data, password)
    

    Objective-C

    https://github.com/Gurpartap/AESCrypt-ObjC

    Here's how you would use the AESCrypt Objective-C class:

    NSString *message = @"top secret message";
    NSString *password = @"p4ssw0rd";
    
    // Encrypting
    NSString *encryptedData = [AESCrypt encrypt:message password:password];
    
    // Decrypting
    NSString *message = [AESCrypt decrypt:encryptedData password:password];
    

    Hope it helps!

提交回复
热议问题