Ich versuche, Benutzername und Passwort zu verschlüsseln und senden Sie es an eine Website mit RSA. Ich habe im Internet gesucht und habe nichts gefunden. ich den öffentlichen Schlüssel aus einer .Net WebServer in XML formal wie folgt aus:Verschlüsseln mit RSA von Swift zu C#
<RSAKeyValue>
<Modulus>vB/j1viHNHdSSnD1JwrZKu93GZtXO/oQAzp90w/QRQC7s7RO4PhTcW3ADOUVB1+BlmbaFsEreNUAOV5P4aZh+68T+InwmU1javFsGkjCcVoQO/uEpp2zjrM9Eh84OPaKH429GVmdfTgUj0YbmYVanM3HX4byMH25DKQD687b7x8=
</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
Also muss ich es mit diesem Schlüssel verschlüsseln, ich bin mit XCode 8 und Swift 3. Mit .Net C · wird sehr leicht.
RSACryptoServiceProvider encryptKey = new RSACryptoServiceProvider();
UnicodeEncoding encoding = new UnicodeEncoding();
encryptKey.FromXmlString(XML PublicKey);
byte[] usr = encryptKey.Encrypt(encoding.GetBytes(txtUser.Text),false);
byte[] pwd = encryptKey.Encrypt(encoding.GetBytes(txtPassword.Text),false);
¿Kann mir bitte jemand helfen? dank
AKTUALISIERT
ich versuche, diesen Code aber mit publicKey wurde in Mac OS funktionieren erzeugt, aber mit einem öffentlichen Schlüssel bekam ich vom Server nicht funktioniert, ich weiß nicht, warum? @Charles Srstka
let pubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDzZtW7ETOkJGTwN/4adYI5oQZ7U7EPzfDtpZTf+cQ9zAcmcC6g6uAC6KuovBSsigcUNzw3s2eNh0RvYBl6ipJ71hH1awTBwVEWo4fl7uIqdpBjwvO1wWXg9UifpvSsV3GPff9YqMvuggDznOGc20CvsXusQKt9dDx8ESxP6yjqiwIDAQAB"
let keyData = NSData(base64Encoded: pubKey, options: NSData.Base64DecodingOptions.ignoreUnknownCharacters)
var dict: [NSString: AnyObject] = [
kSecClass: kSecClassKey,
kSecAttrKeyType: kSecAttrKeyTypeRSA,
kSecAttrKeySizeInBits: pubKey.utf8.count as AnyObject,
kSecAttrKeyClass: kSecAttrKeyClassPublic,
kSecAttrApplicationTag: "me.lhu" as AnyObject,
kSecValueData: keyData as AnyObject,
kSecReturnRef: true as AnyObject
];
SecItemDelete(dict as CFDictionary)
var err = SecItemAdd(dict as CFDictionary, nil);
if ((err != noErr)) {
print("error loading public key");
}
var resultData: SecKey? = nil
var result: AnyObject?
err = SecItemCopyMatching(dict as CFDictionary, &result)
if err == noErr, let keyRef as! SecKey {
let plaintext = tf_taikhoan.text
let plaintextLen = plaintext?.lengthOfBytes(using: String.Encoding.utf8)
let plaintextBytes = [UInt8](plaintext!.utf8)
var encryptedLen: Int = SecKeyGetBlockSize(keyRef)
var encryptedBytes = [UInt8](repeating: 0, count: encryptedLen)
err = SecKeyEncrypt(keyRef, SecPadding.PKCS1, plaintextBytes, plaintextLen!, &encryptedBytes, &encryptedLen);
if (err != noErr) {
print(encryptedBytes);
}
}
@El Tomato Ich denke das ist sein C# Code, nicht Swift. –
meine Client-Seite ist iOS Swift und Server-Seite ist WebAPI C# @CharlesSrstka –