Skip to content

Commit

Permalink
Update example.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
scribetw committed Jan 16, 2023
1 parent c719607 commit 9aae3ab
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'dart:io';

import 'package:xml/xml.dart';
import 'package:xml_crypto/xml_crypto.dart';
import 'package:xpath_selector_xml_parser/xpath_selector_xml_parser.dart';

void main() {
final xml = "<library>"
Expand All @@ -20,7 +19,7 @@ void main() {

print('xml signed successfully');

var signedXml = File('result.xml').readAsStringSync();
final signedXml = File('result.xml').readAsStringSync();
print('validating signature...');

//validate an xml document
Expand All @@ -41,10 +40,10 @@ void signXml(String xml, String xpath, String key, String dest) {

bool validateXml(String xml, String key) {
final doc = XmlDocument.parse(xml);
final signature = XmlXPath.node(doc).query("/*/*[local-name()='Signature']").node;
final signature = doc.findAllElements('Signature').first;
final sig = SignedXml()
..keyInfoProvider = FileKeyInfo(key)
..loadSignature(signature!.node);
..loadSignature(signature);
final res = sig.checkSignature(xml);
if (!res) print(sig.validationErrors);
return res;
Expand Down

0 comments on commit 9aae3ab

Please sign in to comment.