Im trying to use the CryptoCommon class but unable the find it in the monotuch assembly.
I found the assembly Mono.Security.Cryptography, does it have the same performance as the CryptoCommon class?
Thanks!!
CommonCrypto is used internally inside Xamarin.iOS, this is not something extra - i.e. there's no need to opt-in or opt-out.
What it means is that it's use is totally transparent to your code. If an algorithm is available in CommonCrypto then using the classic .NET type will use it.
E.g.
// this will use CommonCrypto. AES is supported by CommonCrypto
// if your device supports it AES can be hardware accelerated
var aes = Aes.Create ();
// this will also use CommonCrypto. SHA-1 is supported by CommonCrypto
// if your device supports it SHA-1 can be hardware accelerated
var sha = new SHA1Managed ();
// this will not use CommonCrypto since the algorithm is not supported by Apple
var r = RIPEMD160.Create ();
More information about CommonCrypto can be found on my blog.
Related
Firebase MLKit on iOS supported a Vision class, primarily used to obtain a Firebase vision object in the following manner:
let vision = Vision.vision()
A VisionTextRecognizer instance from the Firebase MLKit API (which also seemingly has no analogue in the Google-MLKit API) can be obtained from the vision object like so:
var recognizer : VisionTextRecognizer = vision.OnDeviceTextRecognizer()
Given the Firebase Mlkit API is deprecated, I'm looking to move the project to the Google-MlKit API and update the codebase accordingly. The migration guide provides a reference to the renamed and functionally equivalent facilities in GoogleMLKit. I cannot find an equivalent for the deprecated Vision and VisionTextRecognizer classes - are these supported in GoogleMLKit?
There is no Vision class in the new Google ML Kit, as mentioned in the Migration Guide:
Domain entry point classes (Vision, NaturalLanguage) no longer exist. They have been replaced by task specific classes. Replace calls to their various factory methods for getting detectors with direct calls to each detector's factory method.
To get an instance of the on-device text recognizer, you can simply do the following:
var recognizer : TextRecognizer = TextRecognizer.textRecognizer()
Or
let recognizer = TextRecognizer.textRecognizer()
Or chain it directly into the inference call:
var recognizedText: Text
do {
recognizedText = try TextRecognizer.textRecognizer().results(in: image)
} catch let error {
// Handle the error
}
See a working example in ML Kit quickstart vision sample app.
As an addendum to the accepted answer, you might encounter the following after an upgrade to MLKit.
If your project relies on a specific version of Protocol Buffers during the upgrade, MLKit might demand a newer version, or compilation errors may point to a missing file in the Protocol buffer headers. It turns out that simply upgrading the relevant pods did not suffice in my case, and I explicitly had to pull in Protobuf-C++ in the Podfile.
I have a Kotlin Multiplatform project setup with Android & cocoapods for iOS.
I have a file Extensions.kt in commonMain/src with the following function:
fun String.isValidEmail(): Boolean {
return validate(ValidatorRegex.EMAIL)
}
I am able to access this function in Android as a String extension:
"abcd#gmail.com".isValidEmail()
But in iOS using Swift, I need to call it as a static method of another class:
ExtensionsKt.isValidEmail("abcd#gmail.com")
It should convert that commonMain/src method to a Swift extension of String instead of a class with a static method.
Am I missing any configuration?
You're doing everything right here. Unfortunately, this option is not available for now. Extensions conversion may be performed correctly for some classes, but Swift's String is not the one. This is a known inconvenience, and K/N team is working hard to make it better.
I have been going through different posts regarding Bit Code option introduced in XCode. As i am creating a project in unity trying to reduce the over the air build size. According to most of the bit code post related to unity they ending up disabling it. my questions are
If i enable the bit code for unity project i know the addition bit
code data will be stripped but does it will decrease the orignal size
of Over-the-air build as right now i have an estimate universal
Download size is 125 MB and i want it to be less then 100MB?
Can i disable the bit code for a specific framework but enable for
project?
Unity Version : 5.3.5f1t
XCode : 7.2
Thanks
As stated here
, bit code is specifically for App Store submission. And extra data will be stripped by App Store only. So I guess in all other cases like ad-hoc/OTA it will not reduce build size.
For your other question, you can use PostProcessing to change these settings.
Here is an example:
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.Collections;
using UnityEditor.iOS.Xcode;
using System.IO;
public class BL_BuildPostProcess
{
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
{
if (buildTarget == BuildTarget.iOS)
{
string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
PBXProject proj = new PBXProject();
proj.ReadFromString(File.ReadAllText(projPath));
string target = proj.TargetGuidByName("Unity-iPhone");
proj.SetBuildProperty(target, "ENABLE_BITCODE", "false");
File.WriteAllText(projPath, proj.WriteToString());
}
}
}
Other references:
IL2CPP Build Size Optimizations
Bitcode Support In IOS & TvOS
hope it helps :)
I'm working on swift project that is scanning QR codes and getting encrypted AES-128 data that needs to be decrypted.
I'm using a framework that is called CryptoSwift.
I have the key and data from QR code that holds the encrypted data.
var key = "B7zqj4TAXnPevYZAR4T26969"
var qrData = "zWDzClfre4aOjTumzGsnpqh4Sje7sFsbKceA3/OSH3nKRwc7/6fYUajBr/bLh9BB"
Edit: Sorry, I forgot to mention that the encryption made with:
Cipher : AES-128
Mode of Operation : CBC
Padding : PKCS7
Key derived from : Simple decoding
I'd like to know what approaches I should do in order to decrypt this QR data.
Any help would be nice.
See this SO answer for sample Swift AES code.
When you say: "Cipher : AES-128" that is ambiguous. presumably you mean a 128-bit key size. The key supplied is 24 bytes which would be a key size of 192-bits.
CBC mode requires an iv but none is specified. Many inmplementations will use 0x00 bytes by default but that is not guaranteed, Common Crypto does. But it is always best to supply the iv.
What do you expect wen you say: "Key derived from : Simple decoding"? The current best practives solution is PBKDF2.
You need a Bridging header and add #import in it. If you dont have a bridging header let the system add one for out, see Adding a Bridging Header, you can delete the .m file after step 3.
You also need to add Security.framework to the project. What version if Swift are you using.
I am looking at the Swift documentation, but I can't find reference to what there's in other languages...
Examples: sin(), cos(), abs() for math, uppercase(), lowercase() for strings, sort(), pop(), push() for arrays etc...
For strings I've found this in the docs:
Swift’s String type is bridged seamlessly to Foundation’s NSString
class. If you are working with the Foundation framework in Cocoa or
Cocoa Touch, the entire NSString API is available to call on any
String value you create, in addition to the String features described
in this chapter. You can also use a String value with any API that
requires an NSString instance.
Could you point me to some doc or where can I find those functions listed?
Looks like this is working...
import Foundation
var theCosOfZero: Double = Double(cos(0)) // theCosOfZero equals 1
The math functions are defined in the Darwin module, so as absolute minimum you have add this:
import Darwin
In most cases import Foundation or import Cocoa will suffice, since those modules import the Darwin module. If you need access to constants like M_PI or similar, navigate with cmd+click to the Darwin module and the to the Darwin.C. Here you would find the C API imports and the Darwin.C.math among them. This way you may examine what's available, already converted to Swift. Nevertheless, all that C API is available with import Darwin.
You cannot issue import Darwin.C.math directly, because you will see the following runtime error (or similar if you're not in the playground):
Playground execution failed: Error in auto-import:
failed to get module 'math' from AST context
Example playground code:
import Darwin
func degToRad(degrees: Double) -> Double {
// M_PI is defined in Darwin.C.math
return M_PI * 2.0 * degrees / 360.0
}
for deg in 0..<360 {
sin(degToRad(Double(deg)))
}
sin(), cos(), abs() are C methods defined in math.h https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/math.3.html
"str".uppercaseString() and "str".lowercaseString() are NSString methods.
sort() is part of the Swift Standard Library, documented at https://developer.apple.com/documentation/swift/array/1688499-sort
Array.append() and Array.removeLast() are also defined in the Swift Standard Library, documented at https://developer.apple.com/documentation/swift/array