1 year ago

#377429

test-img

4kr4m

SwiftyRSA transformation to match "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" in kotlin

Implementing RSA encryption on kotlin is so simple first of all I used transformation "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" then we changed it to support SHA-256 and changing the above code to "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" everything worked perfectly.

The the swift code, to match "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" using SwiftyRSA you need to set the padding to OAEP.

And after changing it in kotlin to support SHA-256 I tried all the values inside SecKey with no luck.

Here is my code how it used to be and it was working fine:

 do {
        let publicKey = try PublicKey(pemNamed: "pubkey")
        let clear = try ClearMessage(string: self, using: .utf8)
        
        let encrypted = try clear.encrypted(with: publicKey, padding: .OAEP)
        
        let base64String = encrypted.base64String
        
        //print(base64String)
        return base64String
    } catch {
        print(error)
        return self
    }

And now I need to change the code to support "RSA/ECB/OAEPWithSHA-256AndMGF1Padding"

swift

encryption

rsa

0 Answers

Your Answer

Accepted video resources