Bonjour,
Je voudrais intégrer la signature électonique (XML, PDF,...) dans mon application Ruby on Rails. Par manque de documentations avec XMLSIG-Ruby, j'ai finalement décidé d'utiliser le Xades de Java pour le faire.
Pour l'intégration, j'utilise JRuby pour la signature.
J'ai trouvé un exemple sur ce site:
http://java.sun.com/developer/techni...signature_api/
Le code Java correspondant est le suivant:
Citation:
// Load the KeyStore and get the signing key and certificate.
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream("mykeystore.jks"), "changeit".toCharArray());
KeyStore.PrivateKeyEntry keyEntry =
(KeyStore.PrivateKeyEntry) ks.getEntry
("mykey", new KeyStore.PasswordProtection("changeit".toCharArray()));
X509Certificate cert = (X509Certificate) keyEntry.getCertificate();
// Create the KeyInfo containing the X509Data.
KeyInfoFactory kif = fac.getKeyInfoFactory();
List x509Content = new ArrayList();
x509Content.add(cert.getSubjectX500Principal().getName());
x509Content.add(cert);
X509Data xd = kif.newX509Data(x509Content);
KeyInfo ki = kif.newKeyInfo(Collections.singletonList(xd));
|
Le code que j'ai écrit avec JRuby est le suivant:
Citation:
require 'java'
include_class 'java.lang.System'
include_class 'java.lang.Object'
include_class('java.lang.String'){|package,name| "J#{name}"}
include_class 'java.io.IOException'
include_class 'java.io.InputStream'
include_class 'java.io.FileOutputStream'
include_class 'java.io.FileInputStream'
include_class 'java.security.KeyStore'
include_class 'java.security.KeyStoreException'
...
password = JString.new("changeit")
ks = KeyStore.getInstance("JKS")
ks.load(FileInputStream.new("keys/keystoreCps.jks"), password.toCharArray())
keyEntry = KeyStore.PrivateKeyEntry.new
keyEntry = ks.getEntry("mykey", KeyStore.PasswordProtection.new(password.toCharArray()))
cert = keyEntry.getCertificate()
#Create the KeyInfo containing the X509Data.
kif = sigFactory.getKeyInfoFactory()
x509Content = ArrayList.new
x509Content.add(cert.getSubjectX500Principal().getName())
x509Content.add(cert)
xd = kif.newX509Data(x509Content)
ki = kif.newKeyInfo(Collections.singletonList(xd))
|
Mais j'ai des messages d'erreurs sur les parties du code que j'ai coloré en rouge.
1) NoMethodError: undefined method `PrivateKeyEntry' for Java::JavaSecurity::KeyStore:Class
2) undefined method `PasswordProtection' for Java::JavaSecurity::KeyStore:Class
Merci de vos réponses pour m'aider à résoudre ce problème.
Vos suggestions et conseils sont aussi les bienvenus pour faire la signature électronique (Xades) avec Ruby.
Bien cordialement,
gsaly.