To give you the context, there is a developer who develops the API of the project and there is a part of the json that will be encrypted. So I have to decipher his content. He has listed all the functions that I will need on the iOs side.
So I have his javascript code and I have to redo the equivalent in swift. He uses the JS library (SJCL) : https://github.com/bitwiseshiftleft/sjcl/
I'm trying to encrypt some text with a public key, but I can't.
First, I generated the private/public keys
let keypair = P256.Signing.PrivateKey() // generation of a key pair
let private_key = keypair.rawRepresentation.base64EncodedString() // private key
print(private_key)
print("------------")
let public_key = keypair.publicKey // public key - DATA
print(public_key)
print("------------")
let publicKeyString = public_key.rawRepresentation.base64EncodedString() // public key - STRING - easy to share
print(publicKeyString)
Now, I'm trying to encrypt a text with the public key..
Here, his javascript code :
var c256 = sjcl.ecc.curves.c256;
var publickeyBas64ToBits = sjcl.codec.base64.toBits(publickey);
console.log(c256);
console.log(publickey);
console.log(publickeyBas64ToBits);
var pub = new sjcl.ecc.elGamal.publicKey(
c256,
publickeyBas64ToBits
)
var ciphertext = sjcl.encrypt(pub, message)
return ciphertext
I don't understand how to do the same thing in swift with CryptoKit :/
Can you help me please ? :)