Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6753333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:08:56+00:00 2026-05-26T13:08:56+00:00

This is the code I am using for the encryption but it generate an

  • 0
This is the code I am using for the encryption but it generate an error 

“CCKeyDerivationPBKDF is unavailable” in AESKeyForPassword method though it is declare before implementation. How to Resolve it.

     #ifndef _CC_PBKDF_H_
#define _CC_PBKDF_H_

#include <sys/types.h>
#include <sys/param.h>

#include <string.h>
#include <limits.h>
#include <stdlib.h>

#include <Availability.h>

#include <CommonCrypto/CommonDigest.h>
#include <CommonCrypto/CommonHMAC.h>


#ifdef __cplusplus
extern "C" {
#endif

    enum {
        kCCPBKDF2 = 2,
    };


    typedef uint32_t CCPBKDFAlgorithm;


    enum {
        kCCPRFHmacAlgSHA1 = 1, 
        kCCPRFHmacAlgSHA224 = 2,
        kCCPRFHmacAlgSHA256 = 3,
        kCCPRFHmacAlgSHA384 = 4,
        kCCPRFHmacAlgSHA512 = 5,
    };


    typedef uint32_t CCPseudoRandomAlgorithm;

    /*

     @function  CCKeyDerivationPBKDF
     @abstract  Derive a key from a text password/passphrase

     @param algorithm       Currently only PBKDF2 is available via kCCPBKDF2
     @param password        The text password used as input to the derivation 
     function.  The actual octets present in this string 
     will be used with no additional processing.  It's 
     extremely important that the same encoding and 
     normalization be used each time this routine is 
     called if the same key is  expected to be derived.
     @param passwordLen     The length of the text password in bytes.
     @param salt            The salt byte values used as input to the derivation 
     function.
     @param saltLen         The length of the salt in bytes.
     @param prf             The Pseudo Random Algorithm to use for the derivation 
     iterations.
     @param rounds          The number of rounds of the Pseudo Random Algorithm 
     to use.
     @param derivedKey      The resulting derived key produced by the function.  
     The space for this must be provided by the caller.
     @param derivedKeyLen   The expected length of the derived key in bytes.

     @discussion The following values are used to designate the PRF:

     * kCCPRFHmacAlgSHA1
     * kCCPRFHmacAlgSHA224
     * kCCPRFHmacAlgSHA256
     * kCCPRFHmacAlgSHA384
     * kCCPRFHmacAlgSHA512

     @result     kCCParamError can result from bad values for the password, salt, 
     and unwrapped key pointers as well as a bad value for the prf function.

     */

    int CCKeyDerivationPBKDF( CCPBKDFAlgorithm algorithm, const char *password, size_t passwordLen,
                             const uint8_t *salt, size_t saltLen,
                             CCPseudoRandomAlgorithm prf, uint rounds, 
                             uint8_t *derivedKey, size_t derivedKeyLen)
    __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);

    /*
     * All lengths are in bytes - not bits.
     */

    /*

     @function  CCCalibratePBKDF
     @abstract  Determine the number of PRF rounds to use for a specific delay on 
     the current platform.  
     @param algorithm       Currently only PBKDF2 is available via kCCPBKDF2
     @param passwordLen     The length of the text password in bytes.
     @param saltLen         The length of the salt in bytes.
     @param prf             The Pseudo Random Algorithm to use for the derivation 
     iterations.
     @param derivedKeyLen   The expected length of the derived key in bytes.
     @param msec            The targetted duration we want to achieve for a key 
     derivation with these parameters.

     @result the number of iterations to use for the desired processing time.

     */

    uint CCCalibratePBKDF(CCPBKDFAlgorithm algorithm, size_t passwordLen, size_t saltLen,
                          CCPseudoRandomAlgorithm prf, size_t derivedKeyLen, uint32_t msec)
    __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);

#ifdef __cplusplus
}
#endif

#endif  /* _CC_PBKDF_H_ */







#import "AESEncryption.h"
#import <CommonCrypto/CommonCryptor.h>
//#import <CommonCrypto/CommonKeyDerivation.h>
//#import <CommonKeyDerivation.h>

@implementation AESEncryption




NSString * const
kRNCryptManagerErrorDomain = @"net.robnapier.RNCryptManager";

const CCAlgorithm kAlgorithm = kCCAlgorithmAES128;
const NSUInteger kAlgorithmKeySize = kCCKeySizeAES128;
const NSUInteger kAlgorithmBlockSize = kCCBlockSizeAES128;
const NSUInteger kAlgorithmIVSize = kCCBlockSizeAES128;
const NSUInteger kPBKDFSaltSize = 8;
const NSUInteger kPBKDFRounds = 1000;//0;  // ~80ms on an iPhone 4

// ===================

+ (NSData *)encryptedDataForData:(NSData *)data
                        password:(NSString *)password
                              iv:(NSData **)iv
                            salt:(NSData **)salt
                           error:(NSError **)error {
    NSAssert(iv, @"IV must not be NULL");
    NSAssert(salt, @"salt must not be NULL");

    *iv = [self randomDataOfLength:kAlgorithmIVSize];
    *salt = [self randomDataOfLength:kPBKDFSaltSize];

    NSData *key = [self AESKeyForPassword:password salt:*salt];

    size_t outLength;
    NSMutableData *
    cipherData = [NSMutableData dataWithLength:data.length +
                  kAlgorithmBlockSize];

    CCCryptorStatus
    result = CCCrypt(kCCEncrypt, // operation
                     kAlgorithm, // Algorithm
                     kCCOptionPKCS7Padding, // options
                     key.bytes, // key
                     key.length, // keylength
                     (*iv).bytes,// iv
                     data.bytes, // dataIn
                     data.length, // dataInLength,
                     cipherData.mutableBytes, // dataOut
                     cipherData.length, // dataOutAvailable
                     &outLength); // dataOutMoved

    if (result == kCCSuccess) {
        cipherData.length = outLength;
    }
    else {
        if (error) {
            *error = [NSError errorWithDomain:kRNCryptManagerErrorDomain
                                         code:result
                                     userInfo:nil];
        }
        return nil;
    }

    return cipherData;
}

// ===================

+ (NSData *)randomDataOfLength:(size_t)length {
    NSMutableData *data = [NSMutableData dataWithLength:length];

    int result = SecRandomCopyBytes(kSecRandomDefault, length,data.mutableBytes);
    NSLog(@"%d",result);
    NSAssert1(result == 0, @"Unable to generate random bytes: %d", errno);
    //NSAssert( @"Unable to generate random bytes: %d", errno);
    return data;
}




// ===================

// Replace this with a 10,000 hash calls if you don't have CCKeyDerivationPBKDF
+ (NSData *)AESKeyForPassword:(NSString *)password 
                         salt:(NSData *)salt {
    NSMutableData *
    derivedKey = [NSMutableData dataWithLength:kAlgorithmKeySize];

    int result = CCKeyDerivationPBKDF(kCCPBKDF2,            // algorithm
                                  password.UTF8String,  // password
                                  password.length,  // passwordLength
                                  salt.bytes,           // salt
                                  salt.length,          // saltLen
                                  kCCPRFHmacAlgSHA1,    // PRF
                                  kPBKDFRounds,         // rounds
                                  derivedKey.mutableBytes, // derivedKey
                                  derivedKey.length); // derivedKeyLen
    NSLog(@"%d",result);
    // Do not log password here
    NSAssert1(result == kCCSuccess,@"Unable to create AES key for password: %d", result);
    //NSAssert(@"Unable to create AES key for password: %d", result);
    return derivedKey;
}
@end

The code placed above implementation is of CommonCrypto/CommonKeyDerivation.h which was not found be me xcode and hence I put code directly at the top.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:08:57+00:00Added an answer on May 26, 2026 at 1:08 pm

    You have merely declared 2 prototypes for CCKeyDerivationPBKDF and CCCalibratePBKDF. Either put the full code for the functions at this place or declare them as extern and have them in a seperate module or library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get an error when I compile this code: using System; public struct Vector2
I'm writing a piece of code to encrypt a text using symmetric encryption. But
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
I have this code :- using (System.Security.Cryptography.SHA256 sha2 = new System.Security.Cryptography.SHA256Managed()) { .. }
I have this code: using DC = MV6DataContext; using MV6; // Business Logic Layer
I found this code using Google. private int RandomNumber(int min, int max) { Random
Suppose this C# code: using (MemoryStream stream = new MemoryStream()) { StreamWriter normalWriter =
I have this code (C#): using System.Collections.Generic; namespace ConsoleApplication1 { public struct Thing {
I am converting some Java code to C#. This code is using getGlyphOutline from
I'm using this code, to make a request to a given URL: private static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.