Este repositório mudou -se para https://codeberg.org/hohlerde/netebics
Esta é uma biblioteca de clientes que implementa o protocolo EBICS para negócios on -line de negócios.
A biblioteca é escrita em C# (7.2) usando o .NET Core 2.x e foi testado com chaves privadas/públicas (arquivos PEM) no Linux/Windows.
Os netebicos são softwares alfa e não devem ser usados para produção . Alterações de API/quebra são muito prováveis.
Os netebics são denpendentes nas seguintes bibliotecas:
Os netebicos não usam injeção de dependência. Consulte o arquivo csproj para obter mais informações.
No momento, não há pacotes oficiais de Nuget disponíveis, então você deve construir a biblioteca por conta própria clonando este repositório.
Verifique se você tem o .NET Core SDK versão 2 ou superior instalado.
Clone o repositório.
git clone https://github.com/hohlerde/NetEbics.git
Construa a biblioteca.
cd NetEbics
dotnet pack -c Release
Você encontrará o pacote NUGET em bin/Release .
Para usar a biblioteca, você deve ter um bom entendimento razoável do protocolo EBICS.
A primeira coisa que você deseja fazer como um novo usuário do EBICS é anunciar suas chaves RSA públicas para o seu banco. Você precisa criar três pares de chave pública/privada para isso (teclas de autenticação, assinatura e criptografia).
Criar as chaves é fácil com o 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 o código acima e também crie uma chave de autenticação ("auth.key") e criptografia ("Enc.key").
Anuncie sua chave de assinatura pública para o seu banco. Observe que as teclas geradas anteriormente são armazenadas no formato PEM e contêm a chave pública e privada.
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 ( ) ) ;Depois disso, precisamos anunciar as teclas de autenticação e criptografia públicas.
// 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 as chaves não é suficiente, pois o banco precisa ter certeza de que as chaves realmente pertencem a você. Para provar isso, você precisa enviar as cartas INI e HIA para o seu banco. Eles contêm valores de hash de suas chaves públicas e sua assinatura escrita. A especificação EBICS descreve em detalhes como essas letras devem ser.
Para se comunicar via EBICS com o banco, você precisa das chaves públicas do banco, porque os dados trocados precisam ser criptografados e 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 ) ; Se você não estiver em um ambiente ASP.NET e deseja ver alguma saída de log, pode, por exemplo, ativar o Serilog, juntamente com o registro do Microsoft Extensions.
Log . Logger = new LoggerConfiguration ( )
. WriteTo . Console ( )
. MinimumLevel . Debug ( )
. CreateLogger ( ) ;
EbicsLogging . MethodLoggingEnabled = true ; // see entry/exit messages in log
EbicsLogging . LoggerFactory . AddSerilog ( ) ; Você precisa fazer referência Serilog.Extensions.Logging e Serilog.Sinks.Console no seu arquivo CSPROJ para usar o Serilog.
< ItemGroup >
< PackageReference Include = " Serilog.Extensions.Logging " Version = " 2.0.2 " />
< PackageReference Include = " Serilog.Sinks.Console " Version = " 3.1.2-dev-00771 " />
</ ItemGroup > Em um ambiente ASP.NET, você só precisa passar na instância LoggerFactory que obtém do contêiner de injeção de dependência para os netebicos.
public MyController ( ILoggerFactory loggerFactory )
{
EbicsLogging . MethodLoggingEnabled = true ;
EbicsLogging . LoggerFactory = loggerFactory ;
}Consulte o arquivo License.txt para obter mais informações.