fileName= fileName.substring(12,19);
//Query the Database and get the blob
Pki publicKey = pkiBO.findPKI(fileName);
//Verifying THe certificate using public key
CertificateFactory cf = null;
try {
cf = CertificateFactory.getInstance("X.509");
} catch (CertificateException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
X509Certificate cert = null;
try {
cert = (X509Certificate)cf.generateCertificate(multipartFile.getInputStream());
} catch (CertificateException | IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try{
String algorithm = "RSA";
KeyFactory keyFactory = KeyFactory.getInstance(algorithm);
EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKey.getCert().getBytes(1,(int) publicKey.getCert().length() ));
PublicKey regenerateThePublicKey = keyFactory.generatePublic(publicKeySpec);
cert.verify(regenerateThePublicKey);
//get the merchant name
if(publicKey!=null)
{
String merchantName = publicKey.getMerchant();
if(!merchantName.isEmpty())
{
// query the database get merchant record
ExternalAccount merchant = externalAccountBO.findAccountByName(merchantName);
double currentBalance = merchant.getCurrentBalance();
currentBalance = currentBalance + publicKey.getAmountInvolved();
merchant.setCurrentBalance(currentBalance);
externalAccountBO.update(merchant);
modelAndView = new ModelAndView("MerchantFileUploadSuccess");
modelAndView.addObject("message",currentBalance);
pkiBO.delete(publicKey);
// Create an External Transaction
ExternalUserTransaction external = new ExternalUserTransaction();
external.setAccessGranted(1);
external.setAmountInvolved(publicKey.getAmountInvolved());
external.setStatus("Approved");
external.setTransDetail(publicKey.getTransDetail());
external.setTransType("Debit");
external.setUserId(merchant.getUserid());
externalTransactionBO.save(external);
}