iPhone: Encrypt Nsstring using AES 128 and Decrypt - iphone

I am new to Encryption/ Decryption. I want to encrypt a NSString variable value using key. Also I want to decrypt the encrypted data . I want to apply AES -128 Algorithm.
Please suggest sample code or useful link.

I found this through a Google search on the terms aes nsstring site:stackoverflow.com:
AES Encryption for an NSString on the iPhone

Related

I am having an error while decrypting with P256keys swift

I am using p256 keys to generate key pair and then SecKeyCreateEncryptedData to encrypt with public key and SecKeyCreateDecryptedData to decrypt with private key. The encryption was successful and able to transfer encrypted data in base64 format to other devices and then while decrypting truncatedASN1Field this error occurs. Please let me know how I can solve this.
This is the link to code snippet https://swiftfiddle.com/6nx5itskhfg5jbtywruoj64kpm
it works when I am using in the same PC but its not working when I am using different ipads to encrypt and decrypt.

Ionic 3 Native AES256 encrypted data is not 24 byte format

We are developing and using the Ionic 3 Native AES 256 algorithm to encrypt the data, the out put of encrypted data is not valid format of ciphertext format(24 byte). so that we can't able to decrypt in java programme side. also our middleware team using AES/GCM/NoPadding but ionic native plugin using AES/CBC/PKCS5PADDING so that we could not able to decrypt the data in java based middleware side. please advise, how do we handle this.
ionic docs : https://ionicframework.com/docs/v3/native/aes256/
As commented in your first question regarding this topic
(ionic v3 AES 256 algorithm to using encrypted not able to decrypt in java AES/GCM/noPadding algorithm) I run the ionic encryption with these data:
password = "test#123"
plaintext = "Test1234"
and received a Base64-encoded ciphertext string like "izMYpAIMvsCKIVjiNztsrA=="
(as the encryptionKey & iv is generated with random elements your results will differ).
Decoding this ciphertext string back to a byte array I get a (byte array) length of 16 and NOT 24 (it has to be always a multiple of 16) so your encryption isn't running well when getting a length of 24!
Second: there is no way to work with different AES modes - ionic does only support CBC mode that has to be used on your middleware decryption as well. If you need to use an authenticated encryption like "GCM" mode you have to use an additional library.

AES256 Encryption with CBC and without padding in Objective-c

I have to do the encryption with AES 256 , CBC and without padding . I have an code which do simple AES256 but requirement is different .
I have an JSON string which i need to pass to the server with AES256/CBC/Nopadding.
Any Help will be appreciated
You can use CommonCrypto to achieve this.
In CCCryptorCreate there is CCOptions parameter, where you should pass 0 (instead of PKCS7Padding constant).

IPhone Decryption with private key -Data Encrypted in Java

Can anyone help with the code how to decrypt with private key ,As in server side they are using OAEP encryption method .I tried decrypting using private key but the decrypted text is Null,I am getting the Error code as -9809 as decryption code result
When you say "with a private key" I assume you mean you're using SecKeyDecrypt() for asymmetric encryption rather than CommonCryptor for symmetric encryption.
SecKeyDecrypt() does not support OAEP. It only supports PKCS1 v1.5 padding (kSecPaddingPKCS1). It can also technically handle ASN.1 padding + PKCS1 padding, but this isn't usually relevant to decryption. You should have noticed this when you passed the SecPadding parameter. What did you pass?
That error number is errSSLCrypto which is a generic "something went wrong in crypto" message.

AES256 Decryption Problem

I have been using the encryption/decryption as detailed here. Following is the scenario :
Retrieved the encrypted data from the server, with utf-8 encoded, xml content.
I am able to decrypt the data to NSData format using the decryption method(AES256 Decryption). But unable to convert the NSData hence obtained to NSString , by using NSUTF8/NSASCII encodings.
the string to decrypt ,key are as follows:
the encryted string:
*Ti6IFA8agg8XdfYQ/bzpW9OkGM3q3bZMsHrT9lRsg27e8la+GqgE
ZiBpVbpFDJ3f1qgaH+vpI0YjsJtvU6rL2YkUHD6rgg3IjyVMmdPtz5U9baPWHFG+/jlWpVULRTP4
PHckEQaQekYo9yjaGWKfWNADzpFUlS99TnWc/Xr/2loWUoatV6mmZDKkIg6sm5BRHaR3MEDoH8bn
quA/RVWc4hc0H4XhMA0f8RsE+i9OhqbqHfkqLss114m9IUICeqBM16mH93VO7jmTTSfSm1YQFSHo
31Lqchmh/baMhaBfd+U1HEkv+Wfop/aaAlKK8Mc7kw+gZMzG+YKGMk7tkAIjepxNK0MD6jxFEtaj
bxPUBSl0ewYXAIFRsS1up44w39MH9L2QrKM7RF1s2SZOvNOD4O1cFr22gGy3GQz+syEV/nn4hest
8koob8RKmUZTNrwkfa4xe8G7FMRYfM8fEpm6gy/hWEvwmNo/X2r3SNo7h5q1x19pBKtO1dBUW8Nf
kV5G5EyBg6HQv9NBcROYKgjLhJ/VNn1SiH+wh2AcsxwG/dELqHfSBWF7c2jDM3ggBCJWf2P/BwKO
eY+g+rHSzAtwtR2tZFZUDHpO/P6GvMw/D7OA7OvqmDWh2jOF4MlzFBCaG7FJAm8BJ2GTCK/V4VQh
nloG2Wgtr4PLCRh8GXZnMCzrvxcR7l47/8Um7u9HcYVg7dUnfuil3r85niUAobN2fdDNrLcjJ8Eg
tanDfPQhz+FBPzt1ygVaYo6Ko3Lq0juHL42vBr4GS2I2UO/wDd+PE6FUL5rXrCHUgL922tnebQuJ
DNIaymNxZ9JLMb2SSSUu*
Key:1ml4nyKW/DggMNhU2qJrvCp80ycHsy32fbSgtdvODGM=
Note:Iam using ECB mode in the ccdecrypt for decryption.As this mode is used at the server side while encrypting data.
Have you see this - Convert UTF-8 encoded NSData to NSString