Skip to content

Commit b4d337a

Browse files
committed
CryptoKit ECDSA key encoding fixes
1 parent 0f3c8ad commit b4d337a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

cryptography-providers/cryptokit/src/commonMain/kotlin/algorithms/CryptoKitEcdsa.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private class EcdsaPublicKey(
8686
override fun encodeToByteArrayBlocking(format: EC.PublicKey.Format): ByteArray = when (format) {
8787
EC.PublicKey.Format.DER -> publicKey.derRepresentation().toByteArray()
8888
EC.PublicKey.Format.JWK -> error("JWK is not supported")
89-
EC.PublicKey.Format.PEM -> publicKey.pemRepresentation().encodeToByteArray()
89+
EC.PublicKey.Format.PEM -> (publicKey.pemRepresentation() + "\n").encodeToByteArray()
9090
EC.PublicKey.Format.RAW -> publicKey.rawRepresentation().toByteArray()
9191
}
9292

@@ -108,7 +108,7 @@ private class EcdsaPrivateKey(
108108
EC.PrivateKey.Format.DER -> privateKey.derRepresentation().toByteArray()
109109
EC.PrivateKey.Format.DER.SEC1 -> TODO()
110110
EC.PrivateKey.Format.JWK -> error("JWK is not supported")
111-
EC.PrivateKey.Format.PEM -> privateKey.pemRepresentation().encodeToByteArray()
111+
EC.PrivateKey.Format.PEM -> (privateKey.pemRepresentation() + "\n").encodeToByteArray()
112112
EC.PrivateKey.Format.PEM.SEC1 -> TODO()
113113
EC.PrivateKey.Format.RAW -> privateKey.rawRepresentation().toByteArray()
114114
}

cryptography-providers/cryptokit/src/commonMain/swift/SwiftEcdsa.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import Foundation
2323
switch curve {
2424
case .p256:
2525
return SwiftEcdsaPublicKey(
26-
key: try P256.Signing.PublicKey(rawRepresentation: rawRepresentation as Data),
26+
key: try P256.Signing.PublicKey(x963Representation: rawRepresentation as Data),
2727
curve: .p256)
2828
case .p384:
2929
return SwiftEcdsaPublicKey(
30-
key: try P384.Signing.PublicKey(rawRepresentation: rawRepresentation as Data),
30+
key: try P384.Signing.PublicKey(x963Representation: rawRepresentation as Data),
3131
curve: .p384)
3232
case .p521:
3333
return SwiftEcdsaPublicKey(
34-
key: try P521.Signing.PublicKey(rawRepresentation: rawRepresentation as Data),
34+
key: try P521.Signing.PublicKey(x963Representation: rawRepresentation as Data),
3535
curve: .p521)
3636
}
3737
}
@@ -122,9 +122,9 @@ import Foundation
122122

123123
@objc public func rawRepresentation() -> Data {
124124
switch curve {
125-
case .p256: return (key as! P256.Signing.PublicKey).rawRepresentation
126-
case .p384: return (key as! P384.Signing.PublicKey).rawRepresentation
127-
case .p521: return (key as! P521.Signing.PublicKey).rawRepresentation
125+
case .p256: return (key as! P256.Signing.PublicKey).x963Representation
126+
case .p384: return (key as! P384.Signing.PublicKey).x963Representation
127+
case .p521: return (key as! P521.Signing.PublicKey).x963Representation
128128
}
129129
}
130130

0 commit comments

Comments
 (0)