Class: Crypto::RSAKey

Inherits:
OpenSSL::PKey::RSA
  • Object
show all
Defined in:
lib/crypto/rsa_key.rb

Overview

Clase para crear llaves privadas, en formato X509 no PKCS7

Para convertirlos vía linea de comandos:

openssl pkcs8 -inform DER -in nombreGiganteDelSAT.key -passin pass:miFIELCreo >> certX509.pem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, password = nil) ⇒ Security::RSAKey

Crea una llave privada

Parameters:

  • file (IO, String)

    El ‘path’ de esta llave o los bytes de la misma

  • password (String, nil) (defaults to: nil)

    El password de esta llave



33
34
35
36
37
38
39
40
41
42
# File 'lib/crypto/rsa_key.rb', line 33

def initialize(file, password = nil)
  @password = password
  if File.file?(file)
    @path = file
    @enc_path = @path + '.enc'
    file = File.read(@path)
  end
  super file, password
  @data = to_s.gsub(/^-.+/, '').delete("\n")
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



23
24
25
# File 'lib/crypto/rsa_key.rb', line 23

def data
  @data
end

#enc_pathObject (readonly)

path de la llave .pem.enc



13
14
15
# File 'lib/crypto/rsa_key.rb', line 13

def enc_path
  @enc_path
end

#enc_pemObject (readonly)

información de la llave en formato .pem.enc



22
23
24
# File 'lib/crypto/rsa_key.rb', line 22

def enc_pem
  @enc_pem
end

#passwordObject (readonly)

contraseña de la llave



16
17
18
# File 'lib/crypto/rsa_key.rb', line 16

def password
  @password
end

#pathObject (readonly)

path de la llave



10
11
12
# File 'lib/crypto/rsa_key.rb', line 10

def path
  @path
end

#pemObject (readonly)

información de la llave en formato .pem



19
20
21
# File 'lib/crypto/rsa_key.rb', line 19

def pem
  @pem
end

Instance Method Details

#encrypt_pem(encrypt_password) ⇒ Object

Encripta el pem generado, requerido para cancelar facturas



56
57
58
59
# File 'lib/crypto/rsa_key.rb', line 56

def encrypt_pem(encrypt_password)
  cipher = OpenSSL::Cipher::Cipher.new('des3')
  return to_pem(cipher, encrypt_password)
end

#seal(text) ⇒ Object

Sella una cadena de texto

Parameters:

  • original_chain (String)

    La cadena a firmar

Returns:

  • La cadena firmada



51
52
53
# File 'lib/crypto/rsa_key.rb', line 51

def seal(text)
  Base64.encode64(sign(OpenSSL::Digest::SHA256.new, text)).delete("\n")
end