How to I get swift to not return a salted cipher text, and instead return an unsalted version of the cipher text?How to get the current time in PythonWhat is the difference between encrypting and signing in asymmetric encryption?How do I get the number of elements in a list?How to check iOS version?RSA decryption using modulus and exponentRSA public key encrypts ASCII value to 0, how to decrypt?C# RSA encryption/decryption with transmissionHow to call Objective-C code from SwiftIn C#, how to decrypt cipher text encrypted in PHP (RSA)?RSA Encryption With String Public Key From Server

How to use the passive form to say "This flower was watered."

programming a recursive formula into Mathematica and find the nth position in the sequence

What are some tips and tricks for finding the cheapest flight when luggage and other fees are not revealed until far into the booking process?

Why is the battery jumpered to a resistor in this schematic?

What's the point of writing that I know will never be used or read?

Adjective or adverb before another adjective

Trying to understand how Digital Certificates and CA are indeed secure

My new Acer Aspire 7 doesn't have a Legacy Boot option, what can I do to get it?

global variant of csname…endcsname

Is this bar slide trick shown on Cheers real or a visual effect?

Airline power sockets shut down when I plug my computer in. How can I avoid that?

Do I need to start off my book by describing the character's "normal world"?

Build a mob of suspiciously happy lenny faces ( ͡° ͜ʖ ͡°)

Can anybody tell me who this Pokemon is?

Has there ever been a truly bilingual country prior to the contemporary period?

Is the Microsoft recommendation to use C# properties applicable to game development?

"I like watching" vs "I like to watch" What's the difference?

How to creat a report of reacurring donors

Expressing a chain of boolean ORs using ILP

What's the relationship betweeen MS-DOS and XENIX?

What would cause a nuclear power plant to break down after 2000 years, but not sooner?

A+ rating still unsecure by Google Chrome's opinion

Is a suspension needed to do wheelies?

What is the purpose/function of this power inductor in parallel?



How to I get swift to not return a salted cipher text, and instead return an unsalted version of the cipher text?


How to get the current time in PythonWhat is the difference between encrypting and signing in asymmetric encryption?How do I get the number of elements in a list?How to check iOS version?RSA decryption using modulus and exponentRSA public key encrypts ASCII value to 0, how to decrypt?C# RSA encryption/decryption with transmissionHow to call Objective-C code from SwiftIn C#, how to decrypt cipher text encrypted in PHP (RSA)?RSA Encryption With String Public Key From Server






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have a swift app that uses a RSA public key to send data to a python server, and have the server decrypt it with the server private key. However, swift returns a different cipher text each time. Is there any way to have it not salt it?



I've tried using SwiftyRSA, and SwiftUtils to implement the encryption, and while asking others for help, it seems swift automatically salts the message.



override func viewDidLoad() 
....
do
let data = "(message!)".data(using: String.Encoding.utf8)!
// tag name to access the stored public key in keychain
let TAG_PUBLIC_KEY = "com.example.keyPublic"
let encryptStr = "encrypted_message="
let encryptStrData = encryptStr.data(using: String.Encoding.utf8)!
let keyString = getKeyStringFromPEMString(PEMString: """
-----BEGIN PUBLIC KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END PUBLIC KEY-----
""")
let encryptedData = try RSAUtils.encryptWithRSAPublicKey(data: data, pubkeyBase64: keyString, tagName: TAG_PUBLIC_KEY)!
let length = encryptStrData.count + encryptedData.count
var array = [UInt8](repeating:0, count:length)
encryptStrData.copyBytes(to: &array, count: encryptStrData.count)
encryptedData.copyBytes(to: &array+encryptStrData.count, count: encryptedData.count)
var st=""
for byte in encryptedData
st += String(format:"%02X", byte)

print("ENCRYPTED MESSAGE")
print(st)

catch
print(error)

...
//Key function - remove header and footer
func getKeyStringFromPEMString(PEMString: String) -> String
let keyArray = PEMString.split(separator: "n") //Remove new line characters
var keyOutput : String = ""
for item in keyArray
if !item.contains("-----") //Example: -----BEGIN PUBLIC KEY-----
keyOutput += item //Join the text together as a single string


return keyOutput

....



from Crypto.PublicKey import RSA
from Crypto import Random
from base64 import b64decode
def decText(encTest):
random_generator = Random.new().read
key = RSA.generate(2048, random_generator)
with open('private.pem','r') as f:
key=RSA.importKey(f.read())
rawCipherData = b64decode(encTest)
decrypted = key.decrypt(encTest)
print(decrypted)
return decrypted


Here's the plaintext.
33ba884d57161df955de45c50e3bba69c83233402bf460906b919bc0806b44356112b6e0b8dd8f2f5804d5b527e996ba91e91015915f03d0292d89b7ecfc3c44



And here's the ciphertext
0C344863CBC6A4D9153C275DE2074C097A153BFBFD2A34F5312FED4BB075FF28DC3CC584A31CBBD1DCCBBFC18417C1B624B9312F67703817B478DBD07A59CD59E62831A833F5ECA07A94C7E55DB59C4F204FA92DEA4C79106FFA66427B8D49ECAC0E962F8466A7BD525624339DC96ABF0D6130113A8A00C0F3581DD87C234667AE3480B8DFD172B54CB0D50CE9F1BCCB5102EF780F3E2C0C6AC9D53D00B8BAF69850E832C9B6A5D324BE6DC8D059D2F123D0D5A89D2BEFAE1D5202D25F558D47821875CAFDAC733A45F53DEFA69CCDD12D50005914E6105C5C055CC4531822862A5A581D0D5FF1EE593A168390319D2466AB0A939C546DAF919979A177FB4288



Here's the hex of what python outputs with this cipher text:
A8 AB FA EF FE 71 7E 3E 19 C0 02 AC 08 7E 0C 0C 01 50 A6 34 85 E2 F1 6D 36 DD 30 B2 FA BC A0 64 B8 C2 A0 3E 40 A7 9A A3 C7 05 E1 55 AD CE 61 64 33 0A 89 30 A4 86 55 74 43 F3 3F 37 45 B6 AC 81 27 26 41 B1 69 A3 0A FC 30 38 5A 03 7D 86 45 55 9F 5C 6A 12 E7 0C 8D 06 0E 84 48 1F 25 F6 0E CD 22 3A E2 DC AE C6 0B 51 F1 C4 52 66 99 49 2F EC E4 48 A1 50 D9 FC 93 5B BC E1 D2 E4 5F CF 83 77 2E D5 87 67 08 3E 80 0B AF 9B 6E 30 37 50 61 0E 21 9E DB 6A A0 01 93 D4 C8 9D EF E9 27 BD BB 36 2F 07 FA 9C 5F D3 42 23 42 48 00 35 B0 11 24 DD 45 83 D1 C2 80 2D B1 B3 DF E7 9E D3 90 2F 60 C7 14 25 20 28 73 BC AB 6E 75 15 27 22 C2 C9 B3 E0 46 1D C2 99 C5 85 E8 F5 D4 D2 A3 1E 5A 59 42 3B FC 2B 48 E4 49 0A 6C 1D D1 2F 27 D3 CF 75 63 41 C5 5A 26 BC 56 EB A3 28 59 A4 32 61 82 A4 2E 41










share|improve this question


























  • The RSA padding has a random part so it is correct that the encryption returns a randomized ciphertext. Without the padding the RSA is seriously unsecure

    – gusto2
    Mar 27 at 12:55











  • So how should I fix this? Is there a way to have python handle this issue?

    – trainboy2019
    Mar 27 at 12:59











  • There is nothing to fix, it is so by design and you should not change it (you can implement your own RSA encryption with static padding, but I strongly voice against such foolishness). Event the ciphertext is randomized, it will decrypt the the same plaintext. Maybe if you update your question and explain why you want to have static output, someone could help you achieve your goal (even other way)

    – gusto2
    Mar 27 at 13:11












  • What the key issue is is that the python script won't decrypt the ciphertext. That's the issue I was referring to. It will not decrypt the ciphertext back to plaintext

    – trainboy2019
    Mar 27 at 13:26











  • what exception do you receive? in the python script - do you cut off the prepended text encrypted_message=? I see the swift code is doing hex encoding, but python base64 decoding

    – gusto2
    Mar 27 at 13:37


















1















I have a swift app that uses a RSA public key to send data to a python server, and have the server decrypt it with the server private key. However, swift returns a different cipher text each time. Is there any way to have it not salt it?



I've tried using SwiftyRSA, and SwiftUtils to implement the encryption, and while asking others for help, it seems swift automatically salts the message.



override func viewDidLoad() 
....
do
let data = "(message!)".data(using: String.Encoding.utf8)!
// tag name to access the stored public key in keychain
let TAG_PUBLIC_KEY = "com.example.keyPublic"
let encryptStr = "encrypted_message="
let encryptStrData = encryptStr.data(using: String.Encoding.utf8)!
let keyString = getKeyStringFromPEMString(PEMString: """
-----BEGIN PUBLIC KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END PUBLIC KEY-----
""")
let encryptedData = try RSAUtils.encryptWithRSAPublicKey(data: data, pubkeyBase64: keyString, tagName: TAG_PUBLIC_KEY)!
let length = encryptStrData.count + encryptedData.count
var array = [UInt8](repeating:0, count:length)
encryptStrData.copyBytes(to: &array, count: encryptStrData.count)
encryptedData.copyBytes(to: &array+encryptStrData.count, count: encryptedData.count)
var st=""
for byte in encryptedData
st += String(format:"%02X", byte)

print("ENCRYPTED MESSAGE")
print(st)

catch
print(error)

...
//Key function - remove header and footer
func getKeyStringFromPEMString(PEMString: String) -> String
let keyArray = PEMString.split(separator: "n") //Remove new line characters
var keyOutput : String = ""
for item in keyArray
if !item.contains("-----") //Example: -----BEGIN PUBLIC KEY-----
keyOutput += item //Join the text together as a single string


return keyOutput

....



from Crypto.PublicKey import RSA
from Crypto import Random
from base64 import b64decode
def decText(encTest):
random_generator = Random.new().read
key = RSA.generate(2048, random_generator)
with open('private.pem','r') as f:
key=RSA.importKey(f.read())
rawCipherData = b64decode(encTest)
decrypted = key.decrypt(encTest)
print(decrypted)
return decrypted


Here's the plaintext.
33ba884d57161df955de45c50e3bba69c83233402bf460906b919bc0806b44356112b6e0b8dd8f2f5804d5b527e996ba91e91015915f03d0292d89b7ecfc3c44



And here's the ciphertext
0C344863CBC6A4D9153C275DE2074C097A153BFBFD2A34F5312FED4BB075FF28DC3CC584A31CBBD1DCCBBFC18417C1B624B9312F67703817B478DBD07A59CD59E62831A833F5ECA07A94C7E55DB59C4F204FA92DEA4C79106FFA66427B8D49ECAC0E962F8466A7BD525624339DC96ABF0D6130113A8A00C0F3581DD87C234667AE3480B8DFD172B54CB0D50CE9F1BCCB5102EF780F3E2C0C6AC9D53D00B8BAF69850E832C9B6A5D324BE6DC8D059D2F123D0D5A89D2BEFAE1D5202D25F558D47821875CAFDAC733A45F53DEFA69CCDD12D50005914E6105C5C055CC4531822862A5A581D0D5FF1EE593A168390319D2466AB0A939C546DAF919979A177FB4288



Here's the hex of what python outputs with this cipher text:
A8 AB FA EF FE 71 7E 3E 19 C0 02 AC 08 7E 0C 0C 01 50 A6 34 85 E2 F1 6D 36 DD 30 B2 FA BC A0 64 B8 C2 A0 3E 40 A7 9A A3 C7 05 E1 55 AD CE 61 64 33 0A 89 30 A4 86 55 74 43 F3 3F 37 45 B6 AC 81 27 26 41 B1 69 A3 0A FC 30 38 5A 03 7D 86 45 55 9F 5C 6A 12 E7 0C 8D 06 0E 84 48 1F 25 F6 0E CD 22 3A E2 DC AE C6 0B 51 F1 C4 52 66 99 49 2F EC E4 48 A1 50 D9 FC 93 5B BC E1 D2 E4 5F CF 83 77 2E D5 87 67 08 3E 80 0B AF 9B 6E 30 37 50 61 0E 21 9E DB 6A A0 01 93 D4 C8 9D EF E9 27 BD BB 36 2F 07 FA 9C 5F D3 42 23 42 48 00 35 B0 11 24 DD 45 83 D1 C2 80 2D B1 B3 DF E7 9E D3 90 2F 60 C7 14 25 20 28 73 BC AB 6E 75 15 27 22 C2 C9 B3 E0 46 1D C2 99 C5 85 E8 F5 D4 D2 A3 1E 5A 59 42 3B FC 2B 48 E4 49 0A 6C 1D D1 2F 27 D3 CF 75 63 41 C5 5A 26 BC 56 EB A3 28 59 A4 32 61 82 A4 2E 41










share|improve this question


























  • The RSA padding has a random part so it is correct that the encryption returns a randomized ciphertext. Without the padding the RSA is seriously unsecure

    – gusto2
    Mar 27 at 12:55











  • So how should I fix this? Is there a way to have python handle this issue?

    – trainboy2019
    Mar 27 at 12:59











  • There is nothing to fix, it is so by design and you should not change it (you can implement your own RSA encryption with static padding, but I strongly voice against such foolishness). Event the ciphertext is randomized, it will decrypt the the same plaintext. Maybe if you update your question and explain why you want to have static output, someone could help you achieve your goal (even other way)

    – gusto2
    Mar 27 at 13:11












  • What the key issue is is that the python script won't decrypt the ciphertext. That's the issue I was referring to. It will not decrypt the ciphertext back to plaintext

    – trainboy2019
    Mar 27 at 13:26











  • what exception do you receive? in the python script - do you cut off the prepended text encrypted_message=? I see the swift code is doing hex encoding, but python base64 decoding

    – gusto2
    Mar 27 at 13:37














1












1








1








I have a swift app that uses a RSA public key to send data to a python server, and have the server decrypt it with the server private key. However, swift returns a different cipher text each time. Is there any way to have it not salt it?



I've tried using SwiftyRSA, and SwiftUtils to implement the encryption, and while asking others for help, it seems swift automatically salts the message.



override func viewDidLoad() 
....
do
let data = "(message!)".data(using: String.Encoding.utf8)!
// tag name to access the stored public key in keychain
let TAG_PUBLIC_KEY = "com.example.keyPublic"
let encryptStr = "encrypted_message="
let encryptStrData = encryptStr.data(using: String.Encoding.utf8)!
let keyString = getKeyStringFromPEMString(PEMString: """
-----BEGIN PUBLIC KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END PUBLIC KEY-----
""")
let encryptedData = try RSAUtils.encryptWithRSAPublicKey(data: data, pubkeyBase64: keyString, tagName: TAG_PUBLIC_KEY)!
let length = encryptStrData.count + encryptedData.count
var array = [UInt8](repeating:0, count:length)
encryptStrData.copyBytes(to: &array, count: encryptStrData.count)
encryptedData.copyBytes(to: &array+encryptStrData.count, count: encryptedData.count)
var st=""
for byte in encryptedData
st += String(format:"%02X", byte)

print("ENCRYPTED MESSAGE")
print(st)

catch
print(error)

...
//Key function - remove header and footer
func getKeyStringFromPEMString(PEMString: String) -> String
let keyArray = PEMString.split(separator: "n") //Remove new line characters
var keyOutput : String = ""
for item in keyArray
if !item.contains("-----") //Example: -----BEGIN PUBLIC KEY-----
keyOutput += item //Join the text together as a single string


return keyOutput

....



from Crypto.PublicKey import RSA
from Crypto import Random
from base64 import b64decode
def decText(encTest):
random_generator = Random.new().read
key = RSA.generate(2048, random_generator)
with open('private.pem','r') as f:
key=RSA.importKey(f.read())
rawCipherData = b64decode(encTest)
decrypted = key.decrypt(encTest)
print(decrypted)
return decrypted


Here's the plaintext.
33ba884d57161df955de45c50e3bba69c83233402bf460906b919bc0806b44356112b6e0b8dd8f2f5804d5b527e996ba91e91015915f03d0292d89b7ecfc3c44



And here's the ciphertext
0C344863CBC6A4D9153C275DE2074C097A153BFBFD2A34F5312FED4BB075FF28DC3CC584A31CBBD1DCCBBFC18417C1B624B9312F67703817B478DBD07A59CD59E62831A833F5ECA07A94C7E55DB59C4F204FA92DEA4C79106FFA66427B8D49ECAC0E962F8466A7BD525624339DC96ABF0D6130113A8A00C0F3581DD87C234667AE3480B8DFD172B54CB0D50CE9F1BCCB5102EF780F3E2C0C6AC9D53D00B8BAF69850E832C9B6A5D324BE6DC8D059D2F123D0D5A89D2BEFAE1D5202D25F558D47821875CAFDAC733A45F53DEFA69CCDD12D50005914E6105C5C055CC4531822862A5A581D0D5FF1EE593A168390319D2466AB0A939C546DAF919979A177FB4288



Here's the hex of what python outputs with this cipher text:
A8 AB FA EF FE 71 7E 3E 19 C0 02 AC 08 7E 0C 0C 01 50 A6 34 85 E2 F1 6D 36 DD 30 B2 FA BC A0 64 B8 C2 A0 3E 40 A7 9A A3 C7 05 E1 55 AD CE 61 64 33 0A 89 30 A4 86 55 74 43 F3 3F 37 45 B6 AC 81 27 26 41 B1 69 A3 0A FC 30 38 5A 03 7D 86 45 55 9F 5C 6A 12 E7 0C 8D 06 0E 84 48 1F 25 F6 0E CD 22 3A E2 DC AE C6 0B 51 F1 C4 52 66 99 49 2F EC E4 48 A1 50 D9 FC 93 5B BC E1 D2 E4 5F CF 83 77 2E D5 87 67 08 3E 80 0B AF 9B 6E 30 37 50 61 0E 21 9E DB 6A A0 01 93 D4 C8 9D EF E9 27 BD BB 36 2F 07 FA 9C 5F D3 42 23 42 48 00 35 B0 11 24 DD 45 83 D1 C2 80 2D B1 B3 DF E7 9E D3 90 2F 60 C7 14 25 20 28 73 BC AB 6E 75 15 27 22 C2 C9 B3 E0 46 1D C2 99 C5 85 E8 F5 D4 D2 A3 1E 5A 59 42 3B FC 2B 48 E4 49 0A 6C 1D D1 2F 27 D3 CF 75 63 41 C5 5A 26 BC 56 EB A3 28 59 A4 32 61 82 A4 2E 41










share|improve this question
















I have a swift app that uses a RSA public key to send data to a python server, and have the server decrypt it with the server private key. However, swift returns a different cipher text each time. Is there any way to have it not salt it?



I've tried using SwiftyRSA, and SwiftUtils to implement the encryption, and while asking others for help, it seems swift automatically salts the message.



override func viewDidLoad() 
....
do
let data = "(message!)".data(using: String.Encoding.utf8)!
// tag name to access the stored public key in keychain
let TAG_PUBLIC_KEY = "com.example.keyPublic"
let encryptStr = "encrypted_message="
let encryptStrData = encryptStr.data(using: String.Encoding.utf8)!
let keyString = getKeyStringFromPEMString(PEMString: """
-----BEGIN PUBLIC KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END PUBLIC KEY-----
""")
let encryptedData = try RSAUtils.encryptWithRSAPublicKey(data: data, pubkeyBase64: keyString, tagName: TAG_PUBLIC_KEY)!
let length = encryptStrData.count + encryptedData.count
var array = [UInt8](repeating:0, count:length)
encryptStrData.copyBytes(to: &array, count: encryptStrData.count)
encryptedData.copyBytes(to: &array+encryptStrData.count, count: encryptedData.count)
var st=""
for byte in encryptedData
st += String(format:"%02X", byte)

print("ENCRYPTED MESSAGE")
print(st)

catch
print(error)

...
//Key function - remove header and footer
func getKeyStringFromPEMString(PEMString: String) -> String
let keyArray = PEMString.split(separator: "n") //Remove new line characters
var keyOutput : String = ""
for item in keyArray
if !item.contains("-----") //Example: -----BEGIN PUBLIC KEY-----
keyOutput += item //Join the text together as a single string


return keyOutput

....



from Crypto.PublicKey import RSA
from Crypto import Random
from base64 import b64decode
def decText(encTest):
random_generator = Random.new().read
key = RSA.generate(2048, random_generator)
with open('private.pem','r') as f:
key=RSA.importKey(f.read())
rawCipherData = b64decode(encTest)
decrypted = key.decrypt(encTest)
print(decrypted)
return decrypted


Here's the plaintext.
33ba884d57161df955de45c50e3bba69c83233402bf460906b919bc0806b44356112b6e0b8dd8f2f5804d5b527e996ba91e91015915f03d0292d89b7ecfc3c44



And here's the ciphertext
0C344863CBC6A4D9153C275DE2074C097A153BFBFD2A34F5312FED4BB075FF28DC3CC584A31CBBD1DCCBBFC18417C1B624B9312F67703817B478DBD07A59CD59E62831A833F5ECA07A94C7E55DB59C4F204FA92DEA4C79106FFA66427B8D49ECAC0E962F8466A7BD525624339DC96ABF0D6130113A8A00C0F3581DD87C234667AE3480B8DFD172B54CB0D50CE9F1BCCB5102EF780F3E2C0C6AC9D53D00B8BAF69850E832C9B6A5D324BE6DC8D059D2F123D0D5A89D2BEFAE1D5202D25F558D47821875CAFDAC733A45F53DEFA69CCDD12D50005914E6105C5C055CC4531822862A5A581D0D5FF1EE593A168390319D2466AB0A939C546DAF919979A177FB4288



Here's the hex of what python outputs with this cipher text:
A8 AB FA EF FE 71 7E 3E 19 C0 02 AC 08 7E 0C 0C 01 50 A6 34 85 E2 F1 6D 36 DD 30 B2 FA BC A0 64 B8 C2 A0 3E 40 A7 9A A3 C7 05 E1 55 AD CE 61 64 33 0A 89 30 A4 86 55 74 43 F3 3F 37 45 B6 AC 81 27 26 41 B1 69 A3 0A FC 30 38 5A 03 7D 86 45 55 9F 5C 6A 12 E7 0C 8D 06 0E 84 48 1F 25 F6 0E CD 22 3A E2 DC AE C6 0B 51 F1 C4 52 66 99 49 2F EC E4 48 A1 50 D9 FC 93 5B BC E1 D2 E4 5F CF 83 77 2E D5 87 67 08 3E 80 0B AF 9B 6E 30 37 50 61 0E 21 9E DB 6A A0 01 93 D4 C8 9D EF E9 27 BD BB 36 2F 07 FA 9C 5F D3 42 23 42 48 00 35 B0 11 24 DD 45 83 D1 C2 80 2D B1 B3 DF E7 9E D3 90 2F 60 C7 14 25 20 28 73 BC AB 6E 75 15 27 22 C2 C9 B3 E0 46 1D C2 99 C5 85 E8 F5 D4 D2 A3 1E 5A 59 42 3B FC 2B 48 E4 49 0A 6C 1D D1 2F 27 D3 CF 75 63 41 C5 5A 26 BC 56 EB A3 28 59 A4 32 61 82 A4 2E 41







python ios swift encryption rsa






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 14:30







trainboy2019

















asked Mar 27 at 12:51









trainboy2019trainboy2019

339 bronze badges




339 bronze badges















  • The RSA padding has a random part so it is correct that the encryption returns a randomized ciphertext. Without the padding the RSA is seriously unsecure

    – gusto2
    Mar 27 at 12:55











  • So how should I fix this? Is there a way to have python handle this issue?

    – trainboy2019
    Mar 27 at 12:59











  • There is nothing to fix, it is so by design and you should not change it (you can implement your own RSA encryption with static padding, but I strongly voice against such foolishness). Event the ciphertext is randomized, it will decrypt the the same plaintext. Maybe if you update your question and explain why you want to have static output, someone could help you achieve your goal (even other way)

    – gusto2
    Mar 27 at 13:11












  • What the key issue is is that the python script won't decrypt the ciphertext. That's the issue I was referring to. It will not decrypt the ciphertext back to plaintext

    – trainboy2019
    Mar 27 at 13:26











  • what exception do you receive? in the python script - do you cut off the prepended text encrypted_message=? I see the swift code is doing hex encoding, but python base64 decoding

    – gusto2
    Mar 27 at 13:37


















  • The RSA padding has a random part so it is correct that the encryption returns a randomized ciphertext. Without the padding the RSA is seriously unsecure

    – gusto2
    Mar 27 at 12:55











  • So how should I fix this? Is there a way to have python handle this issue?

    – trainboy2019
    Mar 27 at 12:59











  • There is nothing to fix, it is so by design and you should not change it (you can implement your own RSA encryption with static padding, but I strongly voice against such foolishness). Event the ciphertext is randomized, it will decrypt the the same plaintext. Maybe if you update your question and explain why you want to have static output, someone could help you achieve your goal (even other way)

    – gusto2
    Mar 27 at 13:11












  • What the key issue is is that the python script won't decrypt the ciphertext. That's the issue I was referring to. It will not decrypt the ciphertext back to plaintext

    – trainboy2019
    Mar 27 at 13:26











  • what exception do you receive? in the python script - do you cut off the prepended text encrypted_message=? I see the swift code is doing hex encoding, but python base64 decoding

    – gusto2
    Mar 27 at 13:37

















The RSA padding has a random part so it is correct that the encryption returns a randomized ciphertext. Without the padding the RSA is seriously unsecure

– gusto2
Mar 27 at 12:55





The RSA padding has a random part so it is correct that the encryption returns a randomized ciphertext. Without the padding the RSA is seriously unsecure

– gusto2
Mar 27 at 12:55













So how should I fix this? Is there a way to have python handle this issue?

– trainboy2019
Mar 27 at 12:59





So how should I fix this? Is there a way to have python handle this issue?

– trainboy2019
Mar 27 at 12:59













There is nothing to fix, it is so by design and you should not change it (you can implement your own RSA encryption with static padding, but I strongly voice against such foolishness). Event the ciphertext is randomized, it will decrypt the the same plaintext. Maybe if you update your question and explain why you want to have static output, someone could help you achieve your goal (even other way)

– gusto2
Mar 27 at 13:11






There is nothing to fix, it is so by design and you should not change it (you can implement your own RSA encryption with static padding, but I strongly voice against such foolishness). Event the ciphertext is randomized, it will decrypt the the same plaintext. Maybe if you update your question and explain why you want to have static output, someone could help you achieve your goal (even other way)

– gusto2
Mar 27 at 13:11














What the key issue is is that the python script won't decrypt the ciphertext. That's the issue I was referring to. It will not decrypt the ciphertext back to plaintext

– trainboy2019
Mar 27 at 13:26





What the key issue is is that the python script won't decrypt the ciphertext. That's the issue I was referring to. It will not decrypt the ciphertext back to plaintext

– trainboy2019
Mar 27 at 13:26













what exception do you receive? in the python script - do you cut off the prepended text encrypted_message=? I see the swift code is doing hex encoding, but python base64 decoding

– gusto2
Mar 27 at 13:37






what exception do you receive? in the python script - do you cut off the prepended text encrypted_message=? I see the swift code is doing hex encoding, but python base64 decoding

– gusto2
Mar 27 at 13:37













1 Answer
1






active

oldest

votes


















1














I see difference in encoding and decoding



in the Swift encryption code the encryption seems to output:



hex_encode( "encrypted_message=" + encrypt( data ) )


while the python is doing



base64_decode( ciphertext )


If there's something else, you will need to provide working and verifiable code sample, inputs you use and exception you get






share|improve this answer

























  • Here's one of the class files I'm using. raw.githubusercontent.com/btnguyen2k/swiftutils/master/…

    – trainboy2019
    Mar 27 at 14:10












  • I updated the post with the inputs and outputs

    – trainboy2019
    Mar 27 at 14:30











  • @trainboy2019 The problem is not in encryption itself, but how you encode and decode data. You need to use the same algorithm and add no additional text. You need to use THE SAME encoding (hex or base64, just keep it the same). And skip the fancy text constants

    – gusto2
    Mar 27 at 14:41












  • Thanks! That was the issue, I got it to work now, the only issue is it throws a lot of garbage data that I have to get rid of, but I can split the text and work from there.

    – trainboy2019
    Mar 27 at 16:54











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55377652%2fhow-to-i-get-swift-to-not-return-a-salted-cipher-text-and-instead-return-an-uns%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I see difference in encoding and decoding



in the Swift encryption code the encryption seems to output:



hex_encode( "encrypted_message=" + encrypt( data ) )


while the python is doing



base64_decode( ciphertext )


If there's something else, you will need to provide working and verifiable code sample, inputs you use and exception you get






share|improve this answer

























  • Here's one of the class files I'm using. raw.githubusercontent.com/btnguyen2k/swiftutils/master/…

    – trainboy2019
    Mar 27 at 14:10












  • I updated the post with the inputs and outputs

    – trainboy2019
    Mar 27 at 14:30











  • @trainboy2019 The problem is not in encryption itself, but how you encode and decode data. You need to use the same algorithm and add no additional text. You need to use THE SAME encoding (hex or base64, just keep it the same). And skip the fancy text constants

    – gusto2
    Mar 27 at 14:41












  • Thanks! That was the issue, I got it to work now, the only issue is it throws a lot of garbage data that I have to get rid of, but I can split the text and work from there.

    – trainboy2019
    Mar 27 at 16:54
















1














I see difference in encoding and decoding



in the Swift encryption code the encryption seems to output:



hex_encode( "encrypted_message=" + encrypt( data ) )


while the python is doing



base64_decode( ciphertext )


If there's something else, you will need to provide working and verifiable code sample, inputs you use and exception you get






share|improve this answer

























  • Here's one of the class files I'm using. raw.githubusercontent.com/btnguyen2k/swiftutils/master/…

    – trainboy2019
    Mar 27 at 14:10












  • I updated the post with the inputs and outputs

    – trainboy2019
    Mar 27 at 14:30











  • @trainboy2019 The problem is not in encryption itself, but how you encode and decode data. You need to use the same algorithm and add no additional text. You need to use THE SAME encoding (hex or base64, just keep it the same). And skip the fancy text constants

    – gusto2
    Mar 27 at 14:41












  • Thanks! That was the issue, I got it to work now, the only issue is it throws a lot of garbage data that I have to get rid of, but I can split the text and work from there.

    – trainboy2019
    Mar 27 at 16:54














1












1








1







I see difference in encoding and decoding



in the Swift encryption code the encryption seems to output:



hex_encode( "encrypted_message=" + encrypt( data ) )


while the python is doing



base64_decode( ciphertext )


If there's something else, you will need to provide working and verifiable code sample, inputs you use and exception you get






share|improve this answer













I see difference in encoding and decoding



in the Swift encryption code the encryption seems to output:



hex_encode( "encrypted_message=" + encrypt( data ) )


while the python is doing



base64_decode( ciphertext )


If there's something else, you will need to provide working and verifiable code sample, inputs you use and exception you get







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 13:56









gusto2gusto2

5,8492 gold badges9 silver badges23 bronze badges




5,8492 gold badges9 silver badges23 bronze badges















  • Here's one of the class files I'm using. raw.githubusercontent.com/btnguyen2k/swiftutils/master/…

    – trainboy2019
    Mar 27 at 14:10












  • I updated the post with the inputs and outputs

    – trainboy2019
    Mar 27 at 14:30











  • @trainboy2019 The problem is not in encryption itself, but how you encode and decode data. You need to use the same algorithm and add no additional text. You need to use THE SAME encoding (hex or base64, just keep it the same). And skip the fancy text constants

    – gusto2
    Mar 27 at 14:41












  • Thanks! That was the issue, I got it to work now, the only issue is it throws a lot of garbage data that I have to get rid of, but I can split the text and work from there.

    – trainboy2019
    Mar 27 at 16:54


















  • Here's one of the class files I'm using. raw.githubusercontent.com/btnguyen2k/swiftutils/master/…

    – trainboy2019
    Mar 27 at 14:10












  • I updated the post with the inputs and outputs

    – trainboy2019
    Mar 27 at 14:30











  • @trainboy2019 The problem is not in encryption itself, but how you encode and decode data. You need to use the same algorithm and add no additional text. You need to use THE SAME encoding (hex or base64, just keep it the same). And skip the fancy text constants

    – gusto2
    Mar 27 at 14:41












  • Thanks! That was the issue, I got it to work now, the only issue is it throws a lot of garbage data that I have to get rid of, but I can split the text and work from there.

    – trainboy2019
    Mar 27 at 16:54

















Here's one of the class files I'm using. raw.githubusercontent.com/btnguyen2k/swiftutils/master/…

– trainboy2019
Mar 27 at 14:10






Here's one of the class files I'm using. raw.githubusercontent.com/btnguyen2k/swiftutils/master/…

– trainboy2019
Mar 27 at 14:10














I updated the post with the inputs and outputs

– trainboy2019
Mar 27 at 14:30





I updated the post with the inputs and outputs

– trainboy2019
Mar 27 at 14:30













@trainboy2019 The problem is not in encryption itself, but how you encode and decode data. You need to use the same algorithm and add no additional text. You need to use THE SAME encoding (hex or base64, just keep it the same). And skip the fancy text constants

– gusto2
Mar 27 at 14:41






@trainboy2019 The problem is not in encryption itself, but how you encode and decode data. You need to use the same algorithm and add no additional text. You need to use THE SAME encoding (hex or base64, just keep it the same). And skip the fancy text constants

– gusto2
Mar 27 at 14:41














Thanks! That was the issue, I got it to work now, the only issue is it throws a lot of garbage data that I have to get rid of, but I can split the text and work from there.

– trainboy2019
Mar 27 at 16:54






Thanks! That was the issue, I got it to work now, the only issue is it throws a lot of garbage data that I have to get rid of, but I can split the text and work from there.

– trainboy2019
Mar 27 at 16:54









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55377652%2fhow-to-i-get-swift-to-not-return-a-salted-cipher-text-and-instead-return-an-uns%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현