cryptoswift

Migrating Common Crypto AESEncryption to CryptoSWIFT as decrypted string turns null in some cases

我的未来我决定 提交于 2020-01-06 06:04:04
问题 Im using the following code to encrypt and decrypt a string using AES Encryption.I'm using common crypto by adding a Bridging Header. extension String { func aesEncrypt(key:String, iv:String, options:Int = kCCOptionPKCS7Padding) -> String? { if let keyData = key.data(using: String.Encoding.utf8), let data = self.data(using: String.Encoding.utf8), let cryptData = NSMutableData(length: Int((data.count)) + kCCBlockSizeAES128) { let keyLength = size_t(kCCKeySizeAES128) let operation: CCOperation

Migrating Common Crypto AESEncryption to CryptoSWIFT as decrypted string turns null in some cases

不羁岁月 提交于 2020-01-06 06:03:47
问题 Im using the following code to encrypt and decrypt a string using AES Encryption.I'm using common crypto by adding a Bridging Header. extension String { func aesEncrypt(key:String, iv:String, options:Int = kCCOptionPKCS7Padding) -> String? { if let keyData = key.data(using: String.Encoding.utf8), let data = self.data(using: String.Encoding.utf8), let cryptData = NSMutableData(length: Int((data.count)) + kCCBlockSizeAES128) { let keyLength = size_t(kCCKeySizeAES128) let operation: CCOperation

Converting objective-c code to swift

天涯浪子 提交于 2020-01-02 10:58:54
问题 I really need some help to convert the objective-c code to swift using CryptoSwift . I'm not sure how to use functions like: bzero , getCString , malloc in Swift. +(NSData*)encryptData:(NSData*)data { static NSString *key = @"BitCave012345678"; char keyPtr[kCCKeySizeAES128+1]; bzero(keyPtr, sizeof(keyPtr)); [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; NSUInteger dataLength = [data length]; size_t bufferSize = dataLength + kCCBlockSizeAES128; void *buffer =

How to convert bytes to NSString after AES CryptoSwift cipher

左心房为你撑大大i 提交于 2020-01-02 07:03:48
问题 I am using CryptoSwift to encrypt data I will be passing in a URL. To do this, I need the datatype of the piece of data to be a String to concatenate into the NSURL request. After encrypting the data it is output in bytes. How can I cast the bytes to a nonsense string to pass in the URL that a PHP script can decrypt? I am able to encrypt into UInt8, however I do not think it is possible to pass it over a URL to PHP script so I need to make it a string. The code: let string = "hello" let input

HMAC SHA256 in Swift 4

别等时光非礼了梦想. 提交于 2019-12-24 00:48:36
问题 I have a string and a key, which i want to generate an HMAC SHA256 from it. Although i'm using 2 libs IDZSwiftCommonCrypto and CryptoSwift and this answer Nothing really worked for me. My source of truth are those 2 websites https://myeasywww.appspot.com/utility/free/online/Crypt_Decrypt-MD5-AES-HMAC-SHA-DES-RABBIT/en?command=UTILITY&ID=2 and https://www.freeformatter.com/hmac-generator.html#ad-output Which they always generate the correct hash key for my case. Any idea in what can work here?

Converting objective-c code to swift

淺唱寂寞╮ 提交于 2019-12-06 11:58:24
I really need some help to convert the objective-c code to swift using CryptoSwift . I'm not sure how to use functions like: bzero , getCString , malloc in Swift. +(NSData*)encryptData:(NSData*)data { static NSString *key = @"BitCave012345678"; char keyPtr[kCCKeySizeAES128+1]; bzero(keyPtr, sizeof(keyPtr)); [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; NSUInteger dataLength = [data length]; size_t bufferSize = dataLength + kCCBlockSizeAES128; void *buffer = malloc(bufferSize); size_t numBytesEncrypted = 0; CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,

How to hash a string to SHA512 in Swift?

百般思念 提交于 2019-12-04 23:06:01
问题 I am building a social media application and I would like some help encoding a password string to SHA512 in Swift. I found the CryptoSwift library on GitHub but I am having a hard time loading it into my Swift project and linking it to my project files. Does anyone know how to accomplish this relatively easily? Thanks in advance, Kyle 回答1: Solution for Swift 3 : extension String { func sha512() -> String { let data = self.data(using: .utf8)! var digest = [UInt8](repeating: 0, count: Int(CC

How to hash a string to SHA512 in Swift?

北战南征 提交于 2019-12-03 13:39:46
I am building a social media application and I would like some help encoding a password string to SHA512 in Swift. I found the CryptoSwift library on GitHub but I am having a hard time loading it into my Swift project and linking it to my project files. Does anyone know how to accomplish this relatively easily? Thanks in advance, Kyle Solution for Swift 3 : extension String { func sha512() -> String { let data = self.data(using: .utf8)! var digest = [UInt8](repeating: 0, count: Int(CC_SHA512_DIGEST_LENGTH)) data.withUnsafeBytes({ _ = CC_SHA512($0, CC_LONG(data.count), &digest) }) return digest

AES Encrypt and Decrypt

倾然丶 夕夏残阳落幕 提交于 2019-11-26 18:39:30
I write an application by swift, i need AES Encrypt and Decrypt functionality, i received encrypted data from another .Net solution, but i can't find something to do it. This is my .net Encryption: public static byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes) { byte[] encryptedBytes = null; byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; using (MemoryStream ms = new MemoryStream()) { using (RijndaelManaged AES = new RijndaelManaged()) { AES.KeySize = 256; AES.BlockSize = 128; var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000); AES.Key = key.GetBytes