GithubHelp home page GithubHelp logo

Comments (4)

MVakas avatar MVakas commented on August 24, 2024

Not working for me for iOS as well. It gives too many errors.

from cross-platform-aes-encryption.

navneet83 avatar navneet83 commented on August 24, 2024

@i5kender @MVakas I had tested all the code provided in this library. Unfortunately, I won't be able to help you with the information you have provided.
What are the errors which you are getting ? Can you create a gist which I can look at ?

from cross-platform-aes-encryption.

i5kender avatar i5kender commented on August 24, 2024

I have used https://github.com/benoitsan/BBAES classes for ios encrption. I have done. Thanks a lot navneet

from cross-platform-aes-encryption.

rishbaranwal avatar rishbaranwal commented on August 24, 2024

I am stuck somewhere in between, please help

This is the function I am using to decrypt in iOS

func aesCBCDecrypt(data: Data, keyData: Data) throws -> Data? {
    let keyLength = keyData.count
    let validKeyLengths = [kCCKeySizeAES128, kCCKeySizeAES192, kCCKeySizeAES256]
    if validKeyLengths.contains(keyLength) == false {
        throw AESError.KeyError(("Invalid key length", keyLength))
    }
    var numBytesDecrypted: size_t = 0
    let options   = CCOptions(kCCOptionPKCS7Padding)
    let cryptLength  = size_t(data.count)
    var cryptData = Data(count: cryptLength)

    let cryptStatus = cryptData.withUnsafeMutableBytes {cryptBytes in
        data.withUnsafeBytes {dataBytes in
            keyData.withUnsafeBytes {keyBytes in
                CCCrypt(CCOperation(kCCDecrypt),
                        CCAlgorithm(kCCAlgorithmAES),
                        options,
                        keyBytes, keyLength + 1,
                        keyBytes,
                        dataBytes, data.count,
                        cryptBytes, cryptLength,
                        &numBytesDecrypted)
            }
        }
    }

This is the function I am using to encrypt in .net

public string EncryptData(string textData, string Encryptionkey)
{
RijndaelManaged objrij = new RijndaelManaged
{
//set the mode for operation of the algorithm
Mode = CipherMode.CBC,
//set the padding mode used in the algorithm.
Padding = PaddingMode.PKCS7,
//set the size, in bits, for the secret key.
KeySize = 256,
//set the block size in bits for the cryptographic operation.
BlockSize = 128
};
//set the symmetric key that is used for encryption & decryption.
byte[] passBytes = Encoding.UTF8.GetBytes(Encryptionkey);
//set the initialization vector (IV) for the symmetric algorithm
byte[] EncryptionkeyBytes = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

                //int len = passBytes.Length;
                //if (len > EncryptionkeyBytes.Length)
                //{
                //     len = EncryptionkeyBytes.Length;
                //}
                //Array.Copy(passBytes, EncryptionkeyBytes, len);

                objrij.Key = passBytes;
                objrij.IV = EncryptionkeyBytes;

                //Creates symmetric AES object with the current key and initialization vector IV.   
                ICryptoTransform objtransform = objrij.CreateEncryptor();
                byte[] textDataByte = Encoding.UTF8.GetBytes(textData);
                //Final transform the test string. 
                return Convert.ToBase64String(objtransform.TransformFinalBlock(textDataByte, 0, textDataByte.Length));
         }

I am not getting the expected output.

Input:

Plain text: dd00bd64-38d6-4d68-b0fc-2bc6389ee9b3
key: abcdef0123456789abcdef0123456789

Output:

\u{05}\u{06}ST\u{07}\u{02}\u{06}\u{05}\u{1F}\0\u{0C}Q\0\u{1A}\u{0C}]68-b0fc-2bc6389ee9b3

Any help is appreciated

from cross-platform-aes-encryption.

Related Issues (20)

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.