NSData-AES Classe de Chiffrement/Déchiffrement dans le Cacao

Je tente de chiffrer/déchiffrer un fichier de texte brut dans mon éditeur de texte. le chiffrement semble bien fonctionner, mais le décryptage ne fonctionne pas, le texte est en place chiffré. Je suis certain que j'ai décrypté le texte, en utilisant le mot que je crypté - ce que quelqu'un pourrait regarder à travers l'extrait de code ci-dessous et de m'aider?

Merci 🙂

Cryptage:

NSAlert *alert = [NSAlert alertWithMessageText:@"Encryption"
                                     defaultButton:@"Set"
                                   alternateButton:@"Cancel"
                                       otherButton:nil
                         informativeTextWithFormat:@"Please enter a password to encrypt your file with:"];
    [alert setIcon:[NSImage imageNamed:@"License.png"]];
    NSSecureTextField *input = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
    [alert setAccessoryView:input];
    NSInteger button = [alert runModal];
    if (button == NSAlertDefaultReturn) {
    [[NSUserDefaults standardUserDefaults] setObject:[input stringValue] forKey:@"password"];   
    NSData *data;
    [self setString:[textView textStorage]];
    NSMutableDictionary *dict = [NSDictionary dictionaryWithObject:NSPlainTextDocumentType
                                                            forKey:NSDocumentTypeDocumentAttribute];
    [textView breakUndoCoalescing];
    data = [[self string] dataFromRange:NSMakeRange(0, [[self string] length])
                     documentAttributes:dict error:outError];
    NSData*encrypt = [data AESEncryptWithPassphrase:[input stringValue]];
    [encrypt writeToFile:[absoluteURL path] atomically:YES];

Décryptage:

    NSAlert *alert = [NSAlert alertWithMessageText:@"Decryption"
                                     defaultButton:@"Open"
                                   alternateButton:@"Cancel"
                                       otherButton:nil
                         informativeTextWithFormat:@"This file has been protected with a password.To view its contents,enter the password below:"];
    [alert setIcon:[NSImage imageNamed:@"License.png"]];
    NSSecureTextField *input = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
    [alert setAccessoryView:input];
    NSInteger button = [alert runModal];
    if (button == NSAlertDefaultReturn) {
    NSLog(@"Entered Password - attempting to decrypt.");    
    NSMutableDictionary *dict = [NSDictionary dictionaryWithObject:NSPlainTextDocumentType
                                                                forKey:NSDocumentTypeDocumentOption];   
    NSData*decrypted = [[NSData dataWithContentsOfFile:[self fileName]] AESDecryptWithPassphrase:[input stringValue]];
    mString = [[NSAttributedString alloc]
               initWithData:decrypted options:dict documentAttributes:NULL
               error:outError];
Où faire la -AESEncryptWithPassphrase: et -AESDecryptWithPassphrase: méthodes venir?
Salut Rob,j'ai eu l'NSData+AES classe (ce qui inclut ces méthodes) ici:iphonedevelopment.blogspot.com/2009/02/...
la question semble avoir fixé lui-même après la modification de la keybits valeur de 128.
David Schiefer: C'est une catégorie, et non une classe. Voir l'Objective-C, Langage de Programmation de document: developer.apple.com/mac/library/documentation/Cocoa/Conceptual/...
Vous voudrez peut-être consulter la RNCryptor bibliothèque qui entoure CommonCrypto.

OriginalL'auteur Pripyat | 2010-04-05