Este repositorio se ha mudado a https://codeberg.org/hohlerde/netebics
Esta es una biblioteca de clientes que implementa el protocolo EBICS para la banca en línea de negocios.
La biblioteca está escrita en C# (7.2) utilizando .NET Core 2.x y se probó con claves privadas/públicas (archivos PEM) en Linux/Windows.
Netebics es el software alfa y no debe usarse para la producción . Es muy probable que los cambios de API/ruptura son muy probables.
Netebics se presenta en las siguientes bibliotecas:
Netebics no usa inyección de dependencia. Consulte el archivo CSProj para obtener más información.
En este momento no hay paquetes oficiales de Nuget disponibles, por lo que debe construir la biblioteca por su cuenta clonando este repositorio.
Asegúrese de tener el .NET Core SDK versión 2 o superior instalado.
Clon el repositorio.
git clone https://github.com/hohlerde/NetEbics.git
Construye la biblioteca.
cd NetEbics
dotnet pack -c Release
Encontrará el paquete Nuget en bin/Release .
Para usar la biblioteca, debe tener una buena comprensión razonable del protocolo EBICS.
Lo primero que desea hacer como un nuevo usuario de EBICS es anunciar sus claves RSA públicas para su banco. Debe crear tres pares de claves públicas/privadas para esto (claves de autenticación, firma y cifrado).
Crear las teclas es fácil con Bouncycastle.
var gen = GeneratorUtilities . GetKeyPairGenerator ( "RSA" ) ;
gen . Init ( new KeyGenerationParameters ( new SecureRandom ( ) , 4096 ) ) ;
var signKeyPair = gen . GenerateKeyPair ( ) ;
using ( TextWriter sw = new StreamWriter ( "sign.key" ) )
{
var pw = new PemWriter ( sw ) ;
pw . WriteObject ( signKeyPair ) ;
sw . Flush ( ) ;
}Ajuste el código anterior y también cree una tecla Authentication ("Auth.Key") y Cifryption ("Enc.Key").
Anuncie su clave de firma pública a su banco. Tenga en cuenta que las claves generadas previamente se almacenan en formato PEM y contienen la clave privada y pública.
AsymmetricCipherKeyPair signKey ;
using ( var sr = new StringReader ( File . ReadAllText ( "sign.key" ) . Trim ( ) ) )
{
var pr = new PemReader ( sr ) ;
signKey = pr . ReadObject ( ) ;
}
var signCert = KeyUtils . CreateX509Certificate2 ( signKey ) ;
var client = EbicsClient . Factory ( ) . Create ( new EbicsConfig
{
Address = "The EBICS URL you got from your bank, i.e. https://ebics-server.com/" ,
Insecure = true ,
TLS = true ,
User = new UserParams
{
HostId = "The host ID of your bank" ,
PartnerId = "Your partner ID you got from your bank" ,
UserId = "Your user ID you got from your bank" ,
SignKeys = new SignKeyPair
{
Version = SignVersion . A005 , // only A005 is supported right now
TimeStamp = DateTime . Now ,
Certificate = signCert // internally we work with keys
}
}
} ) ;
var resp = c . INI ( new IniParams ( ) ) ;Después de eso, debemos anunciar las claves de autenticación y cifrado pública.
// loading of keys "auth.key" and "enc.key" omitted
var authCert = KeyUtils . CreateX509Certificate2 ( authKey ) ;
var encCert = KeyUtils . CreateX509Certificate2 ( encKey ) ;
var client = EbicsClient . Factory ( ) . Create ( new EbicsConfig
{
Address = "The EBICS URL you got from your bank, i.e. https://ebics-server.com/" ,
Insecure = true ,
TLS = true ,
User = new UserParams
{
HostId = "The host ID of your bank" ,
PartnerId = "Your partner ID" ,
UserId = "Your user ID" ,
AuthKeys = new AuthKeyPair
{
Version = AuthVersion . X002 ,
TimeStamp = DateTime . Now ,
Certificate = authCert
} ,
CryptKeys = new CryptKeyPair
{
Version = CryptVersion . E002 ,
TimeStamp = DateTime . Now ,
Certificate = encCert
}
}
} ) ;
var resp = c . HIA ( new HiaParams ( ) ) ;Anunciar las llaves no es suficiente, ya que el banco debe asegurarse de que las claves realmente le pertenecen. Para probar esto, debe enviar las cartas de INI y HIA a su banco. Contienen valores hash de sus claves públicas y su firma escrita. La especificación EBICS describe en detalle cómo deberían verse estas letras.
Para comunicarse a través de EBIC con el banco, necesita las claves públicas del banco, porque los datos intercambiados deben estar encriptados y autenticados.
// loading of keys "auth.key" and "enc.key" omitted
var authCert = KeyUtils . CreateX509Certificate2 ( authKey ) ;
var encCert = KeyUtils . CreateX509Certificate2 ( encKey ) ;
var client = EbicsClient . Factory ( ) . Create ( new EbicsConfig
{
Address = "The EBICS URL you got from your bank, i.e. https://ebics-server.com/" ,
Insecure = true ,
TLS = true ,
User = new UserParams
{
HostId = "The host ID of your bank" ,
PartnerId = "Your partner ID" ,
UserId = "Your user ID" ,
AuthKeys = new AuthKeyPair
{
Version = AuthVersion . X002 ,
TimeStamp = DateTime . Now ,
Certificate = authCert
} ,
CryptKeys = new CryptKeyPair
{
Version = CryptVersion . E002 ,
TimeStamp = DateTime . Now ,
Certificate = encCert
}
}
} ) ;
var hpbResp = c . HPB ( new HpbParams ( ) ) ;
if ( hpbResp . TechnicalReturnCode != 0 || hpbResp . BusinessReturnCode != 0 )
{
// handle error
return ;
}
c . Config . Bank = resp . Bank ; // set bank's public keys
// now issue other commands // loading of keys "auth.key", "enc.key" and "sign.key" omitted
var authCert = KeyUtils . CreateX509Certificate2 ( authKey ) ;
var encCert = KeyUtils . CreateX509Certificate2 ( encKey ) ;
var signCert = KeyUtils . CreateX509Certificate2 ( signKey ) ;
var client = EbicsClient . Factory ( ) . Create ( new EbicsConfig
{
Address = "The EBICS URL you got from your bank, i.e. https://ebics-server.com/" ,
Insecure = true ,
TLS = true ,
User = new UserParams
{
HostId = "The host ID of your bank" ,
PartnerId = "Your partner ID" ,
UserId = "Your user ID" ,
AuthKeys = new AuthKeyPair
{
Version = AuthVersion . X002 ,
TimeStamp = DateTime . Now ,
Certificate = authCert
} ,
CryptKeys = new CryptKeyPair
{
Version = CryptVersion . E002 ,
TimeStamp = DateTime . Now ,
Certificate = encCert
} ,
SignKeys = new SignKeyPair
{
Version = SignVersion . A005 ,
TimeStamp = DateTime . Now ,
Certificate = signCert
}
}
} ) ;
var hpbResp = c . HPB ( new HpbParams ( ) ) ;
if ( hpbResp . TechnicalReturnCode != 0 || hpbResp . BusinessReturnCode != 0 )
{
// handle error
return ;
}
c . Config . Bank = resp . Bank ; // set bank's public keys
// create credit transfer data structure
var cctParams = new CctParams
{
InitiatingParty = "Your name" ,
PaymentInfos = new [ ]
{
new CreditTransferPaymentInfo
{
DebtorName = "Sender's name" ,
DebtorAccount = "Sender's IBAN" ,
DebtorAgent = "Sender's BIC" ,
ExecutionDate = "2018-05-15" ,
CreditTransferTransactionInfos = new [ ]
{
new CreditTransferTransactionInfo
{
Amount = "1.00" ,
CreditorName = "Receiver's name" ,
CreditorAccount = "Receiver's IBAN" ,
CreditorAgent = "Receiver's BIC" ,
CurrencyCode = "EUR" ,
EndToEndId = "something" ,
RemittanceInfo = "Unstructured information for receiver" ,
}
}
}
}
} ;
var cctResp = c . CCT ( cctParams ) ; Si no está en un entorno ASP.NET y desea ver alguna salida de registro, por ejemplo, puede habilitar SERILOG junto con el registro de Microsoft Extensions.
Log . Logger = new LoggerConfiguration ( )
. WriteTo . Console ( )
. MinimumLevel . Debug ( )
. CreateLogger ( ) ;
EbicsLogging . MethodLoggingEnabled = true ; // see entry/exit messages in log
EbicsLogging . LoggerFactory . AddSerilog ( ) ; Debe hacer referencia Serilog.Extensions.Logging y Serilog.Sinks.Console en su archivo csproj para usar serilog.
< ItemGroup >
< PackageReference Include = " Serilog.Extensions.Logging " Version = " 2.0.2 " />
< PackageReference Include = " Serilog.Sinks.Console " Version = " 3.1.2-dev-00771 " />
</ ItemGroup > En un entorno ASP.NET, solo necesita pasar la instancia LoggerFactory que obtiene del contenedor de inyección de dependencia a Netebics.
public MyController ( ILoggerFactory loggerFactory )
{
EbicsLogging . MethodLoggingEnabled = true ;
EbicsLogging . LoggerFactory = loggerFactory ;
}Consulte el archivo License.txt para obtener más información.