|
1 | 1 | # ------------------------------------------------------------------------------------ |
2 | 2 | # <copyright company="Aspose" file="words_api.rb"> |
3 | | -# Copyright (c) 2023 Aspose.Words for Cloud |
| 3 | +# Copyright (c) 2024 Aspose.Words for Cloud |
4 | 4 | # </copyright> |
5 | 5 | # <summary> |
6 | 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
@@ -36,6 +36,7 @@ class WordsApi |
36 | 36 |
|
37 | 37 | def initialize(api_client = ApiClient.default) |
38 | 38 | @api_client = api_client |
| 39 | + @api_client.config.encryptor = self |
39 | 40 | @rsa_key = nil |
40 | 41 | require_all '../models/requests' |
41 | 42 | require_all '../models/responses' |
@@ -14383,14 +14384,13 @@ def encrypt(data) |
14383 | 14384 | modulus = @api_client.config.modulus |
14384 | 14385 | exponent = @api_client.config.exponent |
14385 | 14386 |
|
14386 | | - if modulus.to_s.empty || exponent.to_s.empty |
14387 | | - data = self.get_public_key GetPublicKeyRequest.new |
14388 | | - modulus = data.modulus |
14389 | | - exponent = data.exponent |
| 14387 | + if (modulus == nil || modulus.to_s.empty?) || (exponent == nil || exponent.to_s.empty?) |
| 14388 | + response = self.get_public_key GetPublicKeyRequest.new |
| 14389 | + modulus = response.modulus |
| 14390 | + exponent = response.exponent |
14390 | 14391 | end |
14391 | 14392 |
|
14392 | | - @rsa_key = OpenSSL::PKey::RSA.new |
14393 | | - @rsa_key.set_key(base64_to_long(modulus), base64_to_long(exponent), nil) |
| 14393 | + @rsa_key = rsa = create_rsa_key(modulus, exponent) |
14394 | 14394 | end |
14395 | 14395 |
|
14396 | 14396 | Base64.encode64(@rsa_key.public_encrypt(data.to_s.force_encoding("utf-8"))) |
@@ -14423,15 +14423,24 @@ def encrypt(data) |
14423 | 14423 | end |
14424 | 14424 | end |
14425 | 14425 |
|
| 14426 | + private def create_rsa_key(n, e) |
| 14427 | + data_sequence = OpenSSL::ASN1::Sequence([ |
| 14428 | + OpenSSL::ASN1::Integer(base64_to_long(n)), |
| 14429 | + OpenSSL::ASN1::Integer(base64_to_long(e)) |
| 14430 | + ]) |
| 14431 | + asn1 = OpenSSL::ASN1::Sequence(data_sequence) |
| 14432 | + OpenSSL::PKey::RSA.new(asn1.to_der) |
| 14433 | + end |
| 14434 | + |
14426 | 14435 | private def base64_to_long(data) |
14427 | | - decoded_with_padding = Base64.urlsafe_decode64(data) + Base64.decode64('==') |
14428 | | - decoded_with_padding.to_s.unpack('C*').map do |byte| |
14429 | | - to_hex(byte) |
| 14436 | + decoded_with_padding = Base64.urlsafe_decode64(data) + Base64.decode64("==") |
| 14437 | + decoded_with_padding.to_s.unpack("C*").map do |byte| |
| 14438 | + byte_to_hex(byte) |
14430 | 14439 | end.join.to_i(16) |
14431 | 14440 | end |
14432 | 14441 |
|
14433 | | - private def to_hex(int) |
14434 | | - int < 16 ? '0' + int.to_s(16) : int.to_s(16) |
| 14442 | + private def byte_to_hex(int) |
| 14443 | + int < 16 ? "0" + int.to_s(16) : int.to_s(16) |
14435 | 14444 | end |
14436 | 14445 | end |
14437 | 14446 | end |
0 commit comments