Abstract
Obtain a builder that can be used to configure signing options for generating a signed certificate from a CSR.
cert := Crypto.cur.certSigner(csr)
.ca(caKeys, "cn=example,ou=example.org,o=Example Inc,c=US")
.notAfter(Date.today + 365day)
.sign
Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:
this < that => <0
this == that => 0
this > that => >0
This method may also be accessed via the <
<=
<=>
>=
and >
shortcut operators. If not overridden the default
implementation compares the toStr
representations. Also see docLang.
Examples:
3.compare(8) => -1
8.compare(3) => 1
8.compare(8) => 0
3 <=> 8 => -1 // shortcut for 3.compare(8)
Compare this object to the specified for equality. This
method may be accessed via the == and != shortcut operators.
If not overridden the default implementation compares for
reference equality using the === operator. If this method
is overridden, then hash() must also be overridden such that
any two objects which return true for equals() must return
the same value for hash(). This method must accept null
and
return false.
Generate a Certificate Signing Request (CSR). The subjectDn
must be a valid X.500
distinguised name as defined in RFC4514.
By default, the implementation should choose a "strong"
signing algorithm for signing the CSR. All implementations
must support the algorithm
option with one of the following
values:
sha256WithRSAEncryption
sha512WithRSAEncryption
// Generate a csr signed with the default algorithm
csr := Crypto.cur.genCsr(pair, "cn=test")
// Generate a csr signed with SHA-512
csr := Crypto.cru.genCsr(pair, "cn=test", ["algorithm": "sha512WithRSAEncryption"])
Generate an asymmetric key pair with the given algorithm and key size (in bits). Throws Err if the algorithm or key size is not supported.
pair := Crypto.cur.genKeyPair("RSA", 2048)
Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.
Attempt to load the full certificate chain for the given uri. If the certificate chain cannot be obtained, throw an sys::Err.
This is an optional operation and implementations may throw sys::UnsupportedErr.
certs := Crypto.cur.loadCertForUri(`https://my.server.com/`)
Load a KeyStore from the given file. If file
is null, then a new, empty keystore in the PKCS12 format
will be returned. The keystore format is determined by the
file extension:
.p12
, .pfx
: PKCS12 format.jks
: Java KeyStore (JAVA only)If the file does not have an extension, then PKCS12 format will be assumed. Other formats may be supported depending on the runtime implementation. Throws an Err if the format is not supported or there is a problem loading the keystore.
The following options may be supported by the implementation:
password
: (Str) - the password used to unlock the keystore
or perform integrity checks.ks := Crypto.cur.loadKeyStore(`keystore.p12`, ["password":"changeit"])
Load the next PEM-encoded object from the input stream. Returns one of the following depending on the PEM encoding:
For PKCS#8, the algorithm
argument will be used for
decoding. This argument is ignored for PKCS#1 where the
alogithm is inferred.
Returns null
if there are no more PEM objects to decode. The
input stream will be closed in this case.
key := Crypto.cur.loadPem(`server.key`) as PrivKey
cert := Crypto.cur.loadPem(`server.pem`) as Cert
Optional
algorithm: stringGet an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:
Return a string representation of this object.
Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:
a->x a.trap("x", null)
a->x() a.trap("x", null)
a->x = b a.trap("x", [b])
a->x(b) a.trap("x", [b])
a->x(b, c) a.trap("x", [b, c])
The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.
This method called whenever an it-block is applied to an
object. The default implementation calls the function with this
,
and then returns this
.
Static
curGet the installed crypto implementation for this runtime.
Static
echoWrite x.toStr
to standard output followed by newline. If x
is null then print "null". If no argument is provided then
print an empty line.
Optional
x: JsObj
Crypto defines a pluggable mixin for cryptography capabilities in Fantom. Use cur to access the current Crypto instance.