summaryrefslogtreecommitdiff
path: root/common/src/main/kotlin/crypto/utils.kt
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/kotlin/crypto/utils.kt')
-rw-r--r--common/src/main/kotlin/crypto/utils.kt16
1 files changed, 6 insertions, 10 deletions
diff --git a/common/src/main/kotlin/crypto/utils.kt b/common/src/main/kotlin/crypto/utils.kt
index 6bad9741..4e272b15 100644
--- a/common/src/main/kotlin/crypto/utils.kt
+++ b/common/src/main/kotlin/crypto/utils.kt
@@ -50,10 +50,7 @@ object CryptoUtil {
val encryptedTransactionKey: ByteArray,
val pubKeyDigest: ByteArray,
val encryptedData: ByteArray,
- /**
- * This key needs to be reused between different upload phases.
- */
- val plainTransactionKey: SecretKey? = null
+ val plainTransactionKey: SecretKey
)
private val bouncyCastleProvider = BouncyCastleProvider()
@@ -130,15 +127,14 @@ object CryptoUtil {
*/
fun getEbicsPublicKeyHash(publicKey: RSAPublicKey): ByteArray {
val keyBytes = ByteArrayOutputStream()
- keyBytes.writeBytes(publicKey.publicExponent.toUnsignedHexString().lowercase().trimStart('0').toByteArray())
+ keyBytes.writeBytes(publicKey.publicExponent.encodeHex().trimStart('0').toByteArray())
keyBytes.write(' '.code)
- keyBytes.writeBytes(publicKey.modulus.toUnsignedHexString().lowercase().trimStart('0').toByteArray())
- // println("buffer before hashing: '${keyBytes.toString(Charsets.UTF_8)}'")
+ keyBytes.writeBytes(publicKey.modulus.encodeHex().trimStart('0').toByteArray())
val digest = MessageDigest.getInstance("SHA-256")
return digest.digest(keyBytes.toByteArray())
}
- fun encryptEbicsE002(data: ByteArray, encryptionPublicKey: RSAPublicKey): EncryptionResult {
+ fun encryptEbicsE002(data: InputStream, encryptionPublicKey: RSAPublicKey): EncryptionResult {
val keygen = KeyGenerator.getInstance("AES", bouncyCastleProvider)
keygen.init(128)
val transactionKey = keygen.generateKey()
@@ -152,7 +148,7 @@ object CryptoUtil {
* Encrypt data according to the EBICS E002 encryption process.
*/
fun encryptEbicsE002withTransactionKey(
- data: ByteArray,
+ data: InputStream,
encryptionPublicKey: RSAPublicKey,
transactionKey: SecretKey
): EncryptionResult {
@@ -162,7 +158,7 @@ object CryptoUtil {
)
val ivParameterSpec = IvParameterSpec(ByteArray(16))
symmetricCipher.init(Cipher.ENCRYPT_MODE, transactionKey, ivParameterSpec)
- val encryptedData = symmetricCipher.doFinal(data)
+ val encryptedData = CipherInputStream(data, symmetricCipher).readAllBytes()
val asymmetricCipher = Cipher.getInstance(
"RSA/None/PKCS1Padding",
bouncyCastleProvider